Skip to content

Commit 90004b9

Browse files
committed
schedule IOLoop.stop on the main thread
loop.stop() will not be safe from a thread in tornado 5 There has never been a guarantee to this effect, but it has happened to be true so far. The result is that the stop event will not fire until the next loop iteration (e.g. triggered by an HTTP request). Using add_callback ensures that the main thread wakes and handles the stop event. cf tornado#2119
1 parent f8d4d6a commit 90004b9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

notebook/notebookapp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,9 @@ def _confirm_exit(self):
12771277
line = sys.stdin.readline()
12781278
if line.lower().startswith(yes) and no not in line.lower():
12791279
self.log.critical(_("Shutdown confirmed"))
1280-
ioloop.IOLoop.current().stop()
1280+
# schedule stop on the main thread,
1281+
# since this might be called from a signal handler
1282+
self.io_loop.add_callback(self.io_loop.stop)
12811283
return
12821284
else:
12831285
print(_("No answer for 5s:"), end=' ')
@@ -1286,11 +1288,11 @@ def _confirm_exit(self):
12861288
# set it back to original SIGINT handler
12871289
# use IOLoop.add_callback because signal.signal must be called
12881290
# from main thread
1289-
ioloop.IOLoop.current().add_callback(self._restore_sigint_handler)
1291+
self.io_loop.add_callback(self._restore_sigint_handler)
12901292

12911293
def _signal_stop(self, sig, frame):
12921294
self.log.critical(_("received signal %s, stopping"), sig)
1293-
ioloop.IOLoop.current().stop()
1295+
self.io_loop.add_callback(self.io_loop.stop)
12941296

12951297
def _signal_info(self, sig, frame):
12961298
print(self.notebook_info())

0 commit comments

Comments
 (0)