Skip to content

Commit

Permalink
Merge pull request ipython#233 from minrk/master
Browse files Browse the repository at this point in the history
Disable parent-poller if PID is 1
  • Loading branch information
minrk authored Mar 29, 2017
2 parents 8a05cf8 + 824f061 commit f8182c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def init_poller(self):
if sys.platform == 'win32':
if self.interrupt or self.parent_handle:
self.poller = ParentPollerWindows(self.interrupt, self.parent_handle)
elif self.parent_handle:
elif self.parent_handle and self.parent_handle != 1:
# PID 1 (init) is special and will never go away,
# only be reassigned.
# Parent polling doesn't work if ppid == 1 to start with.
self.poller = ParentPollerUnix()

def _bind_socket(self, s, port):
Expand Down
4 changes: 4 additions & 0 deletions ipykernel/parentpoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from thread import interrupt_main # Py 2
from threading import Thread

from traitlets.log import get_logger

import warnings

class ParentPollerUnix(Thread):
Expand All @@ -32,6 +34,7 @@ def run(self):
while True:
try:
if os.getppid() == 1:
get_logger().warning("Parent appears to have exited, shutting down.")
os._exit(1)
time.sleep(1.0)
except OSError as e:
Expand Down Expand Up @@ -103,6 +106,7 @@ def run(self):
interrupt_main()

elif handle == self.parent_handle:
get_logger().warning("Parent appears to have exited, shutting down.")
os._exit(1)
elif result < 0:
# wait failed, just give up and stop polling.
Expand Down

0 comments on commit f8182c8

Please sign in to comment.