Skip to content

Commit

Permalink
Merge pull request #336 from minrk/atexit-teardown
Browse files Browse the repository at this point in the history
handle classes having been torn down in atexit
  • Loading branch information
takluyver authored Jan 17, 2018
2 parents 78951c3 + cd73530 commit 162cf6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def __init__(self, context=None, session=None, address=None):
@staticmethod
@atexit.register
def _notice_exit():
HBChannel._exiting = True
# Class definitions can be torn down during interpreter shutdown.
# We only need to set _exiting flag if this hasn't happened.
if HBChannel is not None:
HBChannel._exiting = True

def _create_socket(self):
if self.socket is not None:
Expand Down
5 changes: 4 additions & 1 deletion jupyter_client/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def __init__(self, loop):
@staticmethod
@atexit.register
def _notice_exit():
IOLoopThread._exiting = True
# Class definitions can be torn down during interpreter shutdown.
# We only need to set _exiting flag if this hasn't happened.
if IOLoopThread is not None:
IOLoopThread._exiting = True

def run(self):
"""Run my loop, ignoring EINTR events in the poller"""
Expand Down

0 comments on commit 162cf6f

Please sign in to comment.