Skip to content

Commit

Permalink
tornado 5: PeriodicCallback loop arg will be removed (#3034)
Browse files Browse the repository at this point in the history
* tornado 5: PeriodicCallback loop arg will be removed

PCs are always run with the current eventloop,
which is what the explicitly passed loop always is for us already

* Don't double-close socket & stream

closing stream closes the socket

* remove now-inaccurate comment
  • Loading branch information
minrk authored and takluyver committed Nov 13, 2017
1 parent 5ede4c1 commit 1deb0ae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions notebook/base/zmqhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ def clear_cookie(self, *args, **kwargs):

def open(self, *args, **kwargs):
self.log.debug("Opening websocket %s", self.request.path)

# start the pinging
if self.ping_interval > 0:
loop = ioloop.IOLoop.current()
self.last_ping = loop.time() # Remember time of last ping
self.last_pong = self.last_ping
self.ping_callback = ioloop.PeriodicCallback(
self.send_ping, self.ping_interval, io_loop=loop,
self.send_ping, self.ping_interval,
)
self.ping_callback.start()
return super(WebSocketMixin, self).open(*args, **kwargs)
Expand All @@ -175,7 +175,7 @@ def send_ping(self):
if self.stream.closed() and self.ping_callback is not None:
self.ping_callback.stop()
return

# check for timeout on pong. Make sure that we really have sent a recent ping in
# case the machine with both server and client has been suspended since the last ping.
now = ioloop.IOLoop.current().time()
Expand Down
5 changes: 1 addition & 4 deletions notebook/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,8 @@ def on_close(self):
for channel, stream in self.channels.items():
if stream is not None and not stream.closed():
stream.on_recv(None)
# close the socket directly, don't wait for the stream
socket = stream.socket
stream.close()
socket.close()


self.channels = {}
self._close_future.set_result(None)

Expand Down
3 changes: 1 addition & 2 deletions notebook/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def stop_buffering(self, kernel_id):
for stream in buffer_info['channels'].values():
if not stream.closed():
stream.on_recv(None)
stream.socket.close()
stream.close()

msg_buffer = buffer_info['buffer']
Expand Down Expand Up @@ -386,7 +385,7 @@ def initialize_culler(self):
self.cull_interval, self.cull_interval_default)
self.cull_interval = self.cull_interval_default
self._culler_callback = PeriodicCallback(
self.cull_kernels, 1000*self.cull_interval, loop)
self.cull_kernels, 1000*self.cull_interval)
self.log.info("Culling kernels with idle durations > %s seconds at %s second intervals ...",
self.cull_idle_timeout, self.cull_interval)
if self.cull_busy:
Expand Down

0 comments on commit 1deb0ae

Please sign in to comment.