add utils.awaitable replacement for gen.maybe_future

gen.maybe_future doesn't accept asyncio coroutines
and asyncio.ensure_future doesn't accept *tornado* coroutines, so do our own thing
This commit is contained in:
Min RK
2018-03-01 17:36:03 +01:00
parent 7b4de150cc
commit b6f634368c
8 changed files with 39 additions and 38 deletions

View File

@@ -23,7 +23,7 @@ from .. import __version__
from .. import orm
from ..objects import Server
from ..spawner import LocalProcessSpawner
from ..utils import url_path_join
from ..utils import awaitable, url_path_join
from ..metrics import (
SERVER_SPAWN_DURATION_SECONDS, ServerSpawnStatus,
PROXY_ADD_DURATION_SECONDS, ProxyAddStatus
@@ -387,11 +387,11 @@ class BaseHandler(RequestHandler):
self.set_hub_cookie(user)
def authenticate(self, data):
return gen.maybe_future(self.authenticator.get_authenticated_user(self, data))
return awaitable(self.authenticator.get_authenticated_user(self, data))
def get_next_url(self, user=None):
"""Get the next_url for login redirect
Defaults to hub base_url /hub/ if user is not running,
otherwise user.url.
"""
@@ -421,7 +421,7 @@ class BaseHandler(RequestHandler):
new_user = username not in self.users
user = self.user_from_username(username)
if new_user:
await gen.maybe_future(self.authenticator.add_user(user))
await awaitable(self.authenticator.add_user(user))
# Only set `admin` if the authenticator returned an explicit value.
if admin is not None and admin != user.admin:
user.admin = admin
@@ -577,7 +577,7 @@ class BaseHandler(RequestHandler):
# hook up spawner._spawn_future so that other requests can await
# this result
finish_spawn_future = spawner._spawn_future = finish_user_spawn()
finish_spawn_future = spawner._spawn_future = awaitable(finish_user_spawn())
def _clear_spawn_future(f):
# clear spawner._spawn_future when it's done
# keep an exception around, though, to prevent repeated implicit spawns