20
20
21
21
from .rate_control import rate
22
22
23
+ makeDaemonic = (platform .system () == "Windows" )
23
24
24
25
# Redefine `Thread.run` to not show a traceback for Spyder when stopping
25
26
# the server by raising a KeyboardInterrupt or SystemExit.
@@ -302,7 +303,7 @@ def start_Qapp(port):
302
303
__m = multiprocessing .Process (target = start_Qapp , args = (__HTTP_PORT ,))
303
304
__m .start ()
304
305
305
- __w = threading .Thread (target = __server .serve_forever )
306
+ __w = threading .Thread (target = __server .serve_forever , daemon = makeDaemonic )
306
307
__w .start ()
307
308
308
309
@@ -335,12 +336,13 @@ def start_websocket_server():
335
336
# Put the websocket server in a separate thread running its own event loop.
336
337
# That works even if some other program (e.g. spyder) already running an
337
338
# async event loop.
338
- __t = threading .Thread (target = start_websocket_server )
339
+ __t = threading .Thread (target = start_websocket_server , daemon = makeDaemonic )
339
340
__t .start ()
340
341
341
342
342
343
def stop_server ():
343
344
"""Shuts down all threads and exits cleanly."""
345
+ print ("in stop server" )
344
346
global __server
345
347
__server .shutdown ()
346
348
@@ -362,18 +364,23 @@ def stop_server():
362
364
raise KeyboardInterrupt
363
365
364
366
if threading .main_thread ().is_alive ():
367
+ print ("main is alive..." )
365
368
sys .exit (0 )
366
369
else :
367
370
#
368
371
# check to see if the event loop is still going, if so join it.
369
372
#
373
+ print ("main is dead.." )
370
374
if __t .is_alive ():
371
375
print ("__t is alive still" )
372
376
if threading .get_ident () != __t .ident :
373
377
print ("but it's not my thread, so I'll join..." )
374
378
__t .join ()
375
379
else :
376
380
print ("__t is alive, but that's my thread! So skip it." )
381
+ else :
382
+ if makeDaemonic :
383
+ sys .exit (0 )
377
384
378
385
# If the main thread has already stopped, the python interpreter
379
386
# is likely just running .join on the two remaining threads (in
0 commit comments