@@ -65,7 +65,7 @@ def a_server(
6565
6666 # prepare an env
6767 env = dict (os .environ )
68- env .update (JUPYTER_TOKEN = a_token )
68+ env .update (JUPYTER_TOKEN = a_token , JUPYTER_PLATFORM_DIRS = "1" )
6969
7070 # start the process
7171 server_proc = Popen (args , cwd = str (tmp_path ), env = env )
@@ -75,36 +75,39 @@ def a_server(
7575 canary_url = f"{ url } favicon.ico"
7676 shutdown_url = f"{ url } api/shutdown?token={ a_token } "
7777
78- retries = 10
78+ wait_until_urlopen (canary_url )
79+
80+ print (f"{ a_server_cmd } is ready..." , flush = True )
81+
82+ yield url
83+
84+ # clean up after server is no longer needed
85+ print (f"{ a_server_cmd } shutting down..." , flush = True )
86+ wait_until_urlopen (shutdown_url , data = [])
87+ server_proc .wait ()
88+ print (f"{ a_server_cmd } is stopped" , flush = True )
89+
7990
91+ def wait_until_urlopen (url , ** kwargs ):
92+ retries = 10
8093 while retries :
94+ time .sleep (1 )
8195 try :
82- urlopen (canary_url )
96+ urlopen (url , ** kwargs )
8397 break
8498 except URLError :
8599 if not retries :
86100 print (
87- f"{ a_server_cmd } not ready, aborting" ,
101+ f"{ url } not ready, aborting" ,
88102 flush = True ,
89103 )
90104 raise
91105 print (
92- f"{ a_server_cmd } not ready, will try again in 0.5s [{ retries } retries]" ,
106+ f"{ url } not ready, will try again in 0.5s [{ retries } retries]" ,
93107 flush = True ,
94108 )
95- time .sleep (0.5 )
96109 retries -= 1
97110
98- print (f"{ a_server_cmd } is ready..." , flush = True )
99-
100- yield url
101-
102- # clean up after server is no longer needed
103- print (f"{ a_server_cmd } shutting down..." , flush = True )
104- urlopen (shutdown_url , data = [])
105- server_proc .wait ()
106- print (f"{ a_server_cmd } is stopped" , flush = True )
107-
108111
109112@fixture
110113def a_server_port_and_token (
0 commit comments