@@ -57,6 +57,7 @@ def start_zmq_server_as_subprocess(zmq_url=None, server_args=[]):
5757    env  =  {'PYTHONPATH' : os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))}
5858    kwargs  =  { 
5959        'stdout' : subprocess .PIPE ,
60+         'stderr' : subprocess .PIPE ,
6061        'env' : env 
6162    }
6263    # Use start_new_session if it's available. Without it, in jupyter the server 
@@ -67,6 +68,11 @@ def start_zmq_server_as_subprocess(zmq_url=None, server_args=[]):
6768    line  =  "" 
6869    while  "zmq_url"  not  in line :
6970        line  =  server_proc .stdout .readline ().strip ().decode ("utf-8" )
71+         if  server_proc .poll () is  not None :
72+             outs , errs  =  server_proc .communicate ()
73+             print (outs .decode ("utf-8" ))
74+             print (errs .decode ("utf-8" ))
75+             raise  RuntimeError ("the meshcat server process exited prematurely with exit code "  +  str (server_proc .poll ()))
7076    zmq_url  =  match_zmq_url (line )
7177    web_url  =  match_web_url (server_proc .stdout .readline ().strip ().decode ("utf-8" ))
7278
@@ -212,9 +218,16 @@ def f(port):
212218                if  sys .version_info .major  >=  3 :
213219                        kwargs ['start_new_session' ] =  True 
214220                config  =  pyngrok .conf .PyngrokConfig (** kwargs )
215-                 self .web_url  =  pyngrok .ngrok .connect (self .fileserver_port , "http" , pyngrok_config = config ) +  "/static/" 
216-                 print ("\n " )  # ensure any pyngrok output is properly terminated. 
221+                 self .web_url  =  pyngrok .ngrok .connect (self .fileserver_port , "http" , pyngrok_config = config )
222+ 
223+                 # pyngrok >= 5.0.0 returns an NgrokTunnel object instead of the string. 
224+                 if  sys .version_info .major  <  3 :
225+                     self .web_url  =  self .web_url .decode ("utf-8" )
226+                 elif  not  isinstance (self .web_url , str ):
227+                     self .web_url  =  self .web_url .public_url 
228+                 self .web_url  +=  "/static/" 
217229
230+                 print ("\n " )  # ensure any pyngrok output is properly terminated. 
218231                def  cleanup ():
219232                    pyngrok .ngrok .kill ()
220233
0 commit comments