Skip to content

Commit d44bde8

Browse files
committed
Pass event loop instead of using current()
1 parent 9a3427c commit d44bde8

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

binderhub/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from tornado.httpserver import HTTPServer
2727
from tornado.log import app_log
2828
from traitlets import (
29+
Any,
2930
Bool,
3031
Bytes,
3132
Dict,
@@ -700,6 +701,8 @@ def _template_path_default(self):
700701
help="Origin to use when emitting events. Defaults to hostname of request when empty",
701702
)
702703

704+
ioloop = Any(help="Event loop to use")
705+
703706
@staticmethod
704707
def add_url_prefix(prefix, handlers):
705708
"""add a url prefix to handlers"""
@@ -727,6 +730,7 @@ def init_pycurl(self):
727730
def initialize(self, *args, **kwargs):
728731
"""Load configuration settings."""
729732
super().initialize(*args, **kwargs)
733+
self.ioloop = tornado.ioloop.IOLoop.current()
730734
self.load_config_file(self.config_file)
731735
# hook up tornado logging
732736
if self.debug:
@@ -839,6 +843,7 @@ def initialize(self, *args, **kwargs):
839843
"auth_enabled": self.auth_enabled,
840844
"event_log": self.event_log,
841845
"normalized_origin": self.normalized_origin,
846+
"ioloop": self.ioloop,
842847
}
843848
)
844849
if self.auth_enabled:
@@ -960,7 +965,7 @@ def start(self, run_loop=True):
960965
if self.builder_required:
961966
asyncio.ensure_future(self.watch_build_pods())
962967
if run_loop:
963-
tornado.ioloop.IOLoop.current().start()
968+
self.ioloop.start()
964969

965970

966971
main = BinderHub.launch_instance

binderhub/build.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import kubernetes.config
1515
from kubernetes import client, watch
16-
from tornado.ioloop import IOLoop
1716
from tornado.log import app_log
1817
from traitlets import Any, Bool, Dict, Integer, Unicode, default
1918
from traitlets.config import LoggingConfigurable
@@ -101,11 +100,7 @@ class BuildExecutor(LoggingConfigurable):
101100
config=True,
102101
)
103102

104-
main_loop = Any()
105-
106-
@default("main_loop")
107-
def _default_main_loop(self):
108-
return IOLoop.current()
103+
main_loop = Any(allow_none=False)
109104

110105
stop_event = Any()
111106

binderhub/builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from prometheus_client import Counter, Gauge, Histogram
1616
from tornado import gen
1717
from tornado.httpclient import HTTPClientError
18-
from tornado.ioloop import IOLoop
1918
from tornado.iostream import StreamClosedError
2019
from tornado.log import app_log
2120
from tornado.queues import Queue
@@ -260,7 +259,7 @@ async def get(self, provider_prefix, _unescaped_spec):
260259
return
261260

262261
# create a heartbeat
263-
IOLoop.current().spawn_callback(self.keep_alive)
262+
self.settings["ioloop"].spawn_callback(self.keep_alive)
264263

265264
spec = spec.rstrip("/")
266265
key = f"{provider_prefix}:{spec}"
@@ -447,6 +446,7 @@ async def get(self, provider_prefix, _unescaped_spec):
447446
git_credentials=provider.git_credentials,
448447
sticky_builds=self.settings["sticky_builds"],
449448
)
449+
build.main_loop = self.settings["ioloop"]
450450
else:
451451
build = BuildClass(
452452
# Commented properties should be set in traitlets config
@@ -467,6 +467,7 @@ async def get(self, provider_prefix, _unescaped_spec):
467467
# log_tail_lines=self.settings["log_tail_lines"],
468468
git_credentials=provider.git_credentials,
469469
# sticky_builds=self.settings["sticky_builds"],
470+
main_loop=self.settings["ioloop"],
470471
)
471472
self.build = build
472473

@@ -491,7 +492,7 @@ def _check_result(future):
491492
# Start building
492493
submit_future = pool.submit(build.submit)
493494
submit_future.add_done_callback(_check_result)
494-
IOLoop.current().add_callback(lambda: submit_future)
495+
self.settings["ioloop"].add_callback(lambda: submit_future)
495496

496497
log_future = None
497498

0 commit comments

Comments
 (0)