##// END OF EJS Templates
use IOLoop.current in a few places...
MinRK -
Show More
@@ -229,9 +229,12 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
229
229
230 # start the pinging
230 # start the pinging
231 if self.ping_interval > 0:
231 if self.ping_interval > 0:
232 self.last_ping = ioloop.IOLoop.instance().time() # Remember time of last ping
232 loop = ioloop.IOLoop.current()
233 self.last_ping = loop.time() # Remember time of last ping
233 self.last_pong = self.last_ping
234 self.last_pong = self.last_ping
234 self.ping_callback = ioloop.PeriodicCallback(self.send_ping, self.ping_interval)
235 self.ping_callback = ioloop.PeriodicCallback(
236 self.send_ping, self.ping_interval, io_loop=loop,
237 )
235 self.ping_callback.start()
238 self.ping_callback.start()
236
239
237 def send_ping(self):
240 def send_ping(self):
@@ -242,7 +245,7 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
242
245
243 # check for timeout on pong. Make sure that we really have sent a recent ping in
246 # check for timeout on pong. Make sure that we really have sent a recent ping in
244 # case the machine with both server and client has been suspended since the last ping.
247 # case the machine with both server and client has been suspended since the last ping.
245 now = ioloop.IOLoop.instance().time()
248 now = ioloop.IOLoop.current().time()
246 since_last_pong = 1e3 * (now - self.last_pong)
249 since_last_pong = 1e3 * (now - self.last_pong)
247 since_last_ping = 1e3 * (now - self.last_ping)
250 since_last_ping = 1e3 * (now - self.last_ping)
248 if since_last_ping < 2*self.ping_interval and since_last_pong > self.ping_timeout:
251 if since_last_ping < 2*self.ping_interval and since_last_pong > self.ping_timeout:
@@ -254,4 +257,4 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
254 self.last_ping = now
257 self.last_ping = now
255
258
256 def on_pong(self, data):
259 def on_pong(self, data):
257 self.last_pong = ioloop.IOLoop.instance().time()
260 self.last_pong = ioloop.IOLoop.current().time()
@@ -886,7 +886,7 b' class NotebookApp(BaseIPythonApplication):'
886 line = sys.stdin.readline()
886 line = sys.stdin.readline()
887 if line.lower().startswith('y') and 'n' not in line.lower():
887 if line.lower().startswith('y') and 'n' not in line.lower():
888 self.log.critical("Shutdown confirmed")
888 self.log.critical("Shutdown confirmed")
889 ioloop.IOLoop.instance().stop()
889 ioloop.IOLoop.current().stop()
890 return
890 return
891 else:
891 else:
892 print("No answer for 5s:", end=' ')
892 print("No answer for 5s:", end=' ')
@@ -895,11 +895,11 b' class NotebookApp(BaseIPythonApplication):'
895 # set it back to original SIGINT handler
895 # set it back to original SIGINT handler
896 # use IOLoop.add_callback because signal.signal must be called
896 # use IOLoop.add_callback because signal.signal must be called
897 # from main thread
897 # from main thread
898 ioloop.IOLoop.instance().add_callback(self._restore_sigint_handler)
898 ioloop.IOLoop.current().add_callback(self._restore_sigint_handler)
899
899
900 def _signal_stop(self, sig, frame):
900 def _signal_stop(self, sig, frame):
901 self.log.critical("received signal %s, stopping", sig)
901 self.log.critical("received signal %s, stopping", sig)
902 ioloop.IOLoop.instance().stop()
902 ioloop.IOLoop.current().stop()
903
903
904 def _signal_info(self, sig, frame):
904 def _signal_info(self, sig, frame):
905 print(self.notebook_info())
905 print(self.notebook_info())
@@ -1002,13 +1002,21 b' class NotebookApp(BaseIPythonApplication):'
1002 b = lambda : browser.open(url_path_join(self.connection_url, uri),
1002 b = lambda : browser.open(url_path_join(self.connection_url, uri),
1003 new=2)
1003 new=2)
1004 threading.Thread(target=b).start()
1004 threading.Thread(target=b).start()
1005
1006 self.io_loop = ioloop.IOLoop.current()
1005 try:
1007 try:
1006 ioloop.IOLoop.instance().start()
1008 self.io_loop.start()
1007 except KeyboardInterrupt:
1009 except KeyboardInterrupt:
1008 info("Interrupted...")
1010 info("Interrupted...")
1009 finally:
1011 finally:
1010 self.cleanup_kernels()
1012 self.cleanup_kernels()
1011 self.remove_server_info_file()
1013 self.remove_server_info_file()
1014
1015 def stop(self):
1016 def _stop():
1017 self.http_server.stop()
1018 self.io_loop.stop()
1019 self.io_loop.add_callback(_stop)
1012
1020
1013
1021
1014 def list_running_servers(profile='default'):
1022 def list_running_servers(profile='default'):
General Comments 0
You need to be logged in to leave comments. Login now