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( |
|
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. |
|
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. |
|
260 | self.last_pong = ioloop.IOLoop.current().time() |
@@ -888,7 +888,7 b' class NotebookApp(BaseIPythonApplication):' | |||||
888 | line = sys.stdin.readline() |
|
888 | line = sys.stdin.readline() | |
889 | if line.lower().startswith('y') and 'n' not in line.lower(): |
|
889 | if line.lower().startswith('y') and 'n' not in line.lower(): | |
890 | self.log.critical("Shutdown confirmed") |
|
890 | self.log.critical("Shutdown confirmed") | |
891 |
ioloop.IOLoop. |
|
891 | ioloop.IOLoop.current().stop() | |
892 | return |
|
892 | return | |
893 | else: |
|
893 | else: | |
894 | print("No answer for 5s:", end=' ') |
|
894 | print("No answer for 5s:", end=' ') | |
@@ -897,11 +897,11 b' class NotebookApp(BaseIPythonApplication):' | |||||
897 | # set it back to original SIGINT handler |
|
897 | # set it back to original SIGINT handler | |
898 | # use IOLoop.add_callback because signal.signal must be called |
|
898 | # use IOLoop.add_callback because signal.signal must be called | |
899 | # from main thread |
|
899 | # from main thread | |
900 |
ioloop.IOLoop. |
|
900 | ioloop.IOLoop.current().add_callback(self._restore_sigint_handler) | |
901 |
|
901 | |||
902 | def _signal_stop(self, sig, frame): |
|
902 | def _signal_stop(self, sig, frame): | |
903 | self.log.critical("received signal %s, stopping", sig) |
|
903 | self.log.critical("received signal %s, stopping", sig) | |
904 |
ioloop.IOLoop. |
|
904 | ioloop.IOLoop.current().stop() | |
905 |
|
905 | |||
906 | def _signal_info(self, sig, frame): |
|
906 | def _signal_info(self, sig, frame): | |
907 | print(self.notebook_info()) |
|
907 | print(self.notebook_info()) | |
@@ -1004,13 +1004,21 b' class NotebookApp(BaseIPythonApplication):' | |||||
1004 | b = lambda : browser.open(url_path_join(self.connection_url, uri), |
|
1004 | b = lambda : browser.open(url_path_join(self.connection_url, uri), | |
1005 | new=2) |
|
1005 | new=2) | |
1006 | threading.Thread(target=b).start() |
|
1006 | threading.Thread(target=b).start() | |
|
1007 | ||||
|
1008 | self.io_loop = ioloop.IOLoop.current() | |||
1007 | try: |
|
1009 | try: | |
1008 |
|
|
1010 | self.io_loop.start() | |
1009 | except KeyboardInterrupt: |
|
1011 | except KeyboardInterrupt: | |
1010 | info("Interrupted...") |
|
1012 | info("Interrupted...") | |
1011 | finally: |
|
1013 | finally: | |
1012 | self.cleanup_kernels() |
|
1014 | self.cleanup_kernels() | |
1013 | self.remove_server_info_file() |
|
1015 | self.remove_server_info_file() | |
|
1016 | ||||
|
1017 | def stop(self): | |||
|
1018 | def _stop(): | |||
|
1019 | self.http_server.stop() | |||
|
1020 | self.io_loop.stop() | |||
|
1021 | self.io_loop.add_callback(_stop) | |||
1014 |
|
1022 | |||
1015 |
|
1023 | |||
1016 | def list_running_servers(profile='default'): |
|
1024 | def list_running_servers(profile='default'): |
@@ -78,7 +78,6 b' class TestContentsManager(TestCase):' | |||||
78 | self.td = self._temp_dir.name |
|
78 | self.td = self._temp_dir.name | |
79 | self.contents_manager = FileContentsManager( |
|
79 | self.contents_manager = FileContentsManager( | |
80 | root_dir=self.td, |
|
80 | root_dir=self.td, | |
81 | log=logging.getLogger() |
|
|||
82 | ) |
|
81 | ) | |
83 |
|
82 | |||
84 | def tearDown(self): |
|
83 | def tearDown(self): |
@@ -6,11 +6,12 b' import sys' | |||||
6 | import time |
|
6 | import time | |
7 | import requests |
|
7 | import requests | |
8 | from contextlib import contextmanager |
|
8 | from contextlib import contextmanager | |
9 | from subprocess import Popen, STDOUT |
|
9 | from threading import Thread, Event | |
10 | from unittest import TestCase |
|
10 | from unittest import TestCase | |
11 |
|
11 | |||
12 | import nose |
|
12 | from tornado.ioloop import IOLoop | |
13 |
|
13 | |||
|
14 | from ..notebookapp import NotebookApp | |||
14 | from IPython.utils.tempdir import TemporaryDirectory |
|
15 | from IPython.utils.tempdir import TemporaryDirectory | |
15 |
|
16 | |||
16 | MAX_WAITTIME = 30 # seconds to wait for notebook server to start |
|
17 | MAX_WAITTIME = 30 # seconds to wait for notebook server to start | |
@@ -50,35 +51,46 b' class NotebookTestBase(TestCase):' | |||||
50 | @classmethod |
|
51 | @classmethod | |
51 | def wait_until_dead(cls): |
|
52 | def wait_until_dead(cls): | |
52 | """Wait for the server process to terminate after shutdown""" |
|
53 | """Wait for the server process to terminate after shutdown""" | |
53 | for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): |
|
54 | cls.notebook_thread.join(timeout=MAX_WAITTIME) | |
54 |
|
|
55 | if cls.notebook_thread.is_alive(): | |
55 | return |
|
56 | raise TimeoutError("Undead notebook server") | |
56 | time.sleep(POLL_INTERVAL) |
|
|||
57 |
|
||||
58 | raise TimeoutError("Undead notebook server") |
|
|||
59 |
|
57 | |||
60 | @classmethod |
|
58 | @classmethod | |
61 | def setup_class(cls): |
|
59 | def setup_class(cls): | |
62 | cls.ipython_dir = TemporaryDirectory() |
|
60 | cls.ipython_dir = TemporaryDirectory() | |
63 | cls.notebook_dir = TemporaryDirectory() |
|
61 | cls.notebook_dir = TemporaryDirectory() | |
64 | notebook_args = [ |
|
62 | app = cls.notebook = NotebookApp( | |
65 | sys.executable, '-c', |
|
63 | port=cls.port, | |
66 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', |
|
64 | port_retries=0, | |
67 | '--port=%d' % cls.port, |
|
65 | open_browser=False, | |
68 | '--port-retries=0', # Don't try any other ports |
|
66 | ipython_dir=cls.ipython_dir.name, | |
69 | '--no-browser', |
|
67 | notebook_dir=cls.notebook_dir.name, | |
70 | '--ipython-dir=%s' % cls.ipython_dir.name, |
|
|||
71 | '--notebook-dir=%s' % cls.notebook_dir.name, |
|
|||
72 | ] |
|
|||
73 | cls.notebook = Popen(notebook_args, |
|
|||
74 | stdout=nose.iptest_stdstreams_fileno(), |
|
|||
75 | stderr=STDOUT, |
|
|||
76 | ) |
|
68 | ) | |
|
69 | ||||
|
70 | # clear log handlers and propagate to root for nose to capture it | |||
|
71 | # needs to be redone after initialize, which reconfigures logging | |||
|
72 | app.log.propagate = True | |||
|
73 | app.log.handlers = [] | |||
|
74 | app.initialize(argv=[]) | |||
|
75 | app.log.propagate = True | |||
|
76 | app.log.handlers = [] | |||
|
77 | started = Event() | |||
|
78 | def start_thread(): | |||
|
79 | loop = IOLoop.current() | |||
|
80 | loop.add_callback(started.set) | |||
|
81 | try: | |||
|
82 | app.start() | |||
|
83 | finally: | |||
|
84 | # set the event, so failure to start doesn't cause a hang | |||
|
85 | started.set() | |||
|
86 | cls.notebook_thread = Thread(target=start_thread) | |||
|
87 | cls.notebook_thread.start() | |||
|
88 | started.wait() | |||
77 | cls.wait_until_alive() |
|
89 | cls.wait_until_alive() | |
78 |
|
90 | |||
79 | @classmethod |
|
91 | @classmethod | |
80 | def teardown_class(cls): |
|
92 | def teardown_class(cls): | |
81 |
cls.notebook. |
|
93 | cls.notebook.stop() | |
82 | cls.wait_until_dead() |
|
94 | cls.wait_until_dead() | |
83 | cls.ipython_dir.cleanup() |
|
95 | cls.ipython_dir.cleanup() | |
84 | cls.notebook_dir.cleanup() |
|
96 | cls.notebook_dir.cleanup() |
General Comments 0
You need to be logged in to leave comments.
Login now