Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make closing jupyter client faster #420

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import atexit
import errno
from threading import Thread
from threading import Thread, Event
import time

import zmq
Expand Down Expand Up @@ -73,6 +73,7 @@ def __init__(self, context=None, session=None, address=None):

# running is False until `.start()` is called
self._running = False
self._exit = Event()
# don't start paused
self._pause = False
self.poller = zmq.Poller()
Expand Down Expand Up @@ -138,7 +139,7 @@ def run(self):
while self._running:
if self._pause:
# just sleep, and skip the rest of the loop
time.sleep(self.time_to_dead)
self._exit.wait(self.time_to_dead)
continue

since_last_heartbeat = 0.0
Expand All @@ -154,7 +155,7 @@ def run(self):
# sleep the remainder of the cycle
remainder = self.time_to_dead - (time.time() - request_time)
if remainder > 0:
time.sleep(remainder)
self._exit.wait(remainder)
continue
else:
# nothing was received within the time limit, signal heart failure
Expand Down Expand Up @@ -183,6 +184,7 @@ def is_beating(self):
def stop(self):
"""Stop the channel's event loop and join its thread."""
self._running = False
self._exit.set()
self.join()
self.close()

Expand Down