mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
Merge pull request #2560 from adelcast/dev/adelcast/shutdown
Jupyterhub: use previous exit strategy for Windows
This commit is contained in:
@@ -2420,15 +2420,23 @@ class JupyterHub(Application):
|
|||||||
pc.start()
|
pc.start()
|
||||||
|
|
||||||
self.log.info("JupyterHub is now running at %s", self.proxy.public_url)
|
self.log.info("JupyterHub is now running at %s", self.proxy.public_url)
|
||||||
|
# Use atexit for Windows, it doesn't have signal handling support
|
||||||
|
if _mswindows:
|
||||||
|
atexit.register(self.atexit)
|
||||||
# register cleanup on both TERM and INT
|
# register cleanup on both TERM and INT
|
||||||
self.init_signal()
|
self.init_signal()
|
||||||
|
|
||||||
def init_signal(self):
|
def init_signal(self):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
for s in (signal.SIGTERM, signal.SIGINT):
|
for s in (signal.SIGTERM, signal.SIGINT):
|
||||||
|
if not _mswindows:
|
||||||
loop.add_signal_handler(
|
loop.add_signal_handler(
|
||||||
s, lambda s=s: asyncio.ensure_future(self.shutdown_cancel_tasks(s))
|
s, lambda s=s: asyncio.ensure_future(self.shutdown_cancel_tasks(s))
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
signal.signal(s, self.win_shutdown_cancel_tasks)
|
||||||
|
|
||||||
|
if not _mswindows:
|
||||||
infosignals = [signal.SIGUSR1]
|
infosignals = [signal.SIGUSR1]
|
||||||
if hasattr(signal, 'SIGINFO'):
|
if hasattr(signal, 'SIGINFO'):
|
||||||
infosignals.append(signal.SIGINFO)
|
infosignals.append(signal.SIGINFO)
|
||||||
@@ -2443,6 +2451,24 @@ class JupyterHub(Application):
|
|||||||
print_ps_info()
|
print_ps_info()
|
||||||
print_stacks()
|
print_stacks()
|
||||||
|
|
||||||
|
def win_shutdown_cancel_tasks(self, signum, frame):
|
||||||
|
self.log.critical("Received signalnum %s, , initiating shutdown...", signum)
|
||||||
|
raise SystemExit(128 + signum)
|
||||||
|
|
||||||
|
_atexit_ran = False
|
||||||
|
|
||||||
|
def atexit(self):
|
||||||
|
"""atexit callback"""
|
||||||
|
if self._atexit_ran:
|
||||||
|
return
|
||||||
|
self._atexit_ran = True
|
||||||
|
# run the cleanup step (in a new loop, because the interrupted one is unclean)
|
||||||
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
|
IOLoop.clear_current()
|
||||||
|
loop = IOLoop()
|
||||||
|
loop.make_current()
|
||||||
|
loop.run_sync(self.cleanup)
|
||||||
|
|
||||||
async def shutdown_cancel_tasks(self, sig):
|
async def shutdown_cancel_tasks(self, sig):
|
||||||
"""Cancel all other tasks of the event loop and initiate cleanup"""
|
"""Cancel all other tasks of the event loop and initiate cleanup"""
|
||||||
self.log.critical("Received signal %s, initiating shutdown...", sig.name)
|
self.log.critical("Received signal %s, initiating shutdown...", sig.name)
|
||||||
|
Reference in New Issue
Block a user