diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 41bec9ea..7ce3fb7b 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -31,7 +31,6 @@ from tornado.log import app_log, access_log, gen_log import tornado.options from tornado import gen, web from tornado.platform.asyncio import AsyncIOMainLoop -AsyncIOMainLoop().install() from traitlets import ( Unicode, Integer, Dict, TraitError, List, Bool, Any, @@ -1643,6 +1642,7 @@ class JupyterHub(Application): @classmethod def launch_instance(cls, argv=None): self = cls.instance() + AsyncIOMainLoop().install() loop = IOLoop.current() loop.add_callback(self.launch_instance_async, argv) try: diff --git a/jupyterhub/tests/conftest.py b/jupyterhub/tests/conftest.py index 3eb272c1..1a0a4471 100644 --- a/jupyterhub/tests/conftest.py +++ b/jupyterhub/tests/conftest.py @@ -45,9 +45,7 @@ def io_loop(request): def _close(): io_loop.clear_current() - if (not ioloop.IOLoop.initialized() or - io_loop is not ioloop.IOLoop.instance()): - io_loop.close(all_fds=True) + io_loop.close(all_fds=True) request.addfinalizer(_close) return io_loop diff --git a/jupyterhub/tests/mocking.py b/jupyterhub/tests/mocking.py index 983fec08..6562a5b0 100644 --- a/jupyterhub/tests/mocking.py +++ b/jupyterhub/tests/mocking.py @@ -1,5 +1,6 @@ """mock utilities for testing""" +import asyncio from concurrent.futures import ThreadPoolExecutor import os import sys @@ -235,6 +236,7 @@ class MockHub(JupyterHub): # to avoid multiple eventloops in the same thread errors from asyncio def cleanup(): + asyncio.set_event_loop(asyncio.new_event_loop()) loop = IOLoop.current() loop.run_sync(self.cleanup) loop.close() diff --git a/jupyterhub/tests/test_services_auth.py b/jupyterhub/tests/test_services_auth.py index 455a8f22..d0e69a8a 100644 --- a/jupyterhub/tests/test_services_auth.py +++ b/jupyterhub/tests/test_services_auth.py @@ -1,3 +1,4 @@ +import asyncio from binascii import hexlify import copy import json @@ -125,6 +126,7 @@ def test_hub_authenticated(request): port = 50505 q = Queue() def run(): + asyncio.set_event_loop(asyncio.new_event_loop()) app = Application([ ('/*', TestHandler), ], login_url=auth.login_url)