Skip to content

Commit

Permalink
Merge pull request #420 from impact27/master
Browse files Browse the repository at this point in the history
Make closing jupyter client faster
  • Loading branch information
minrk authored Feb 15, 2019
2 parents cf7cdb8 + 1e9194a commit e813086
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit e813086

Please sign in to comment.