mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
use asyncio.ensure_future to start coroutines immediately
asyncio has different coroutine start mechanics than tornado tornado starts coroutines immediately, whereas asyncio doesn't until they are scheduled with either ensure_future or waited upon.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
# Copyright (c) Jupyter Development Team.
|
# Copyright (c) Jupyter Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import atexit
|
import atexit
|
||||||
import binascii
|
import binascii
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -1286,7 +1287,7 @@ class JupyterHub(Application):
|
|||||||
# spawner should be running
|
# spawner should be running
|
||||||
# instantiate Spawner wrapper and check if it's still alive
|
# instantiate Spawner wrapper and check if it's still alive
|
||||||
spawner = user.spawners[name]
|
spawner = user.spawners[name]
|
||||||
f = check_spawner(user, name, spawner)
|
f = asyncio.ensure_future(check_spawner(user, name, spawner))
|
||||||
check_futures.append(f)
|
check_futures.append(f)
|
||||||
|
|
||||||
# await checks after submitting them all
|
# await checks after submitting them all
|
||||||
@@ -1477,7 +1478,7 @@ class JupyterHub(Application):
|
|||||||
if managed_services:
|
if managed_services:
|
||||||
self.log.info("Cleaning up %i services...", len(managed_services))
|
self.log.info("Cleaning up %i services...", len(managed_services))
|
||||||
for service in managed_services:
|
for service in managed_services:
|
||||||
futures.append(service.stop())
|
futures.append(asyncio.ensure_future(service.stop()))
|
||||||
|
|
||||||
if self.cleanup_servers:
|
if self.cleanup_servers:
|
||||||
self.log.info("Cleaning up single-user servers...")
|
self.log.info("Cleaning up single-user servers...")
|
||||||
@@ -1485,7 +1486,7 @@ class JupyterHub(Application):
|
|||||||
for uid, user in self.users.items():
|
for uid, user in self.users.items():
|
||||||
for name, spawner in list(user.spawners.items()):
|
for name, spawner in list(user.spawners.items()):
|
||||||
if spawner.active:
|
if spawner.active:
|
||||||
futures.append(user.stop(name))
|
futures.append(asyncio.ensure_future(user.stop(name)))
|
||||||
else:
|
else:
|
||||||
self.log.info("Leaving single-user servers running")
|
self.log.info("Leaving single-user servers running")
|
||||||
|
|
||||||
|
@@ -385,7 +385,7 @@ class User:
|
|||||||
try:
|
try:
|
||||||
# run optional preparation work to bootstrap the notebook
|
# run optional preparation work to bootstrap the notebook
|
||||||
await awaitable(spawner.run_pre_spawn_hook())
|
await awaitable(spawner.run_pre_spawn_hook())
|
||||||
f = spawner.start()
|
f = awaitable(spawner.start())
|
||||||
# commit any changes in spawner.start (always commit db changes before yield)
|
# commit any changes in spawner.start (always commit db changes before yield)
|
||||||
db.commit()
|
db.commit()
|
||||||
ip_port = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
|
ip_port = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
|
||||||
|
Reference in New Issue
Block a user