Skip to content

Commit 317f703

Browse files
committed
possibly better check for event loop still going
1 parent 487f866 commit 317f703

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

vpython/no_notebook.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import copy
1515
import socket
1616
import multiprocessing
17+
import pdb
1718

1819

1920
import signal
@@ -51,7 +52,6 @@ def run(*args, **kwargs):
5152
def signal_handler(signal, frame):
5253
stop_server()
5354

54-
5555
signal.signal(signal.SIGINT, signal_handler)
5656

5757
# Requests from client to http server can be the following:
@@ -211,7 +211,10 @@ async def onMessage(self, data, isBinary):
211211
# message format used by notebook
212212
msg = {'content': {'data': [m]}}
213213
loop = asyncio.get_event_loop()
214-
await loop.run_in_executor(None, GW.handle_msg, msg)
214+
try:
215+
await loop.run_in_executor(None, GW.handle_msg, msg)
216+
except:
217+
pass
215218

216219
def onClose(self, wasClean, code, reason):
217220
"""Called when browser tab is closed."""
@@ -355,17 +358,23 @@ def stop_server():
355358
if threading.main_thread().is_alive():
356359
sys.exit(0)
357360
else:
361+
#
362+
# check to see if the event loop is still going, if so join it.
363+
#
364+
if __t.is_alive():
365+
__t.join()
366+
358367
# If the main thread has already stopped, the python interpreter
359368
# is likely just running .join on the two remaining threads (in
360369
# python/threading.py:_shutdown). Since we just stopped those threads,
361370
# we'll now exit.
362-
sys.exit(0) # but just in case....
363-
364-
371+
365372
GW = GlowWidget()
366373

367374
while not (httpserving and websocketserving): # try to make sure setup is complete
368375
rate(60)
369376

377+
370378
# Dummy variable to import
371379
_ = None
380+

0 commit comments

Comments
 (0)