Skip to content

Commit

Permalink
Merge pull request ipython#360 from n8vm/master
Browse files Browse the repository at this point in the history
Handle signal exceptions, fix for issue 11258
  • Loading branch information
minrk authored Oct 8, 2018
2 parents 6900503 + c562f46 commit 7267f5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ def initialize(self, argv=None):
# file is definitely available at the time someone reads the log.
self.log_connection_info()
self.init_io()
self.init_signal()
try:
self.init_signal()
except:
# Catch exception when initializing signal fails, eg when running the
# kernel on a separate thread
if self.log_level < logging.CRITICAL:
self.log.error("Unable to initialize signal:", exc_info=True)
self.init_kernel()
# shell init steps
self.init_path()
Expand Down
10 changes: 8 additions & 2 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,19 @@ def dispatch_shell(self, stream, msg):
self.log.warning("Unknown message type: %r", msg_type)
else:
self.log.debug("%s: %s", msg_type, msg)
self.pre_handler_hook()
try:
self.pre_handler_hook()
except Exception:
self.log.debug("Unable to signal in pre_handler_hook:", exc_info=True)
try:
yield gen.maybe_future(handler(stream, idents, msg))
except Exception:
self.log.error("Exception in message handler:", exc_info=True)
finally:
self.post_handler_hook()
try:
self.post_handler_hook()
except Exception:
self.log.debug("Unable to signal in post_handler_hook:", exc_info=True)

sys.stdout.flush()
sys.stderr.flush()
Expand Down

0 comments on commit 7267f5d

Please sign in to comment.