mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 13:33:00 +00:00
tornado 5 fixes
- ._running private attribute is removed. We don't need it anymore, since we were only using it while the application was run in a background thread. - call blocking cleanup in a thread because asyncio doesn't allow multiple loops in one thread.
This commit is contained in:
@@ -1625,9 +1625,6 @@ class JupyterHub(Application):
|
||||
if not self.io_loop:
|
||||
return
|
||||
if self.http_server:
|
||||
if self.io_loop._running:
|
||||
self.io_loop.add_callback(self.http_server.stop)
|
||||
else:
|
||||
self.http_server.stop()
|
||||
self.io_loop.add_callback(self.io_loop.stop)
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
"""mock utilities for testing"""
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import os
|
||||
import sys
|
||||
from tempfile import NamedTemporaryFile
|
||||
@@ -229,7 +230,21 @@ class MockHub(JupyterHub):
|
||||
|
||||
def stop(self):
|
||||
super().stop()
|
||||
IOLoop().run_sync(self.cleanup)
|
||||
|
||||
# run cleanup in a background thread
|
||||
# to avoid multiple eventloops in the same thread errors from asyncio
|
||||
|
||||
def cleanup():
|
||||
loop = IOLoop.current()
|
||||
loop.run_sync(self.cleanup)
|
||||
loop.close()
|
||||
|
||||
pool = ThreadPoolExecutor(1)
|
||||
f = pool.submit(cleanup)
|
||||
# wait for cleanup to finish
|
||||
f.result()
|
||||
pool.shutdown()
|
||||
|
||||
# ignore the call that will fire in atexit
|
||||
self.cleanup = lambda : None
|
||||
self.db_file.close()
|
||||
|
Reference in New Issue
Block a user