Skip to content

Commit

Permalink
tornado: Replace deprecated IOLoop.instance alias.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <anders@zulip.com>
  • Loading branch information
andersk committed Mar 17, 2022
1 parent cf42e66 commit a9472c2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tools/run-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def log_request(self, handler: BaseHandler) -> None:


def shutdown_handler(*args: Any, **kwargs: Any) -> None:
io_loop = IOLoop.instance()
io_loop = IOLoop.current()
if io_loop._callbacks:
io_loop.call_later(1, shutdown_handler)
else:
Expand Down Expand Up @@ -373,7 +373,7 @@ def print_listeners() -> None:

print_listeners()

ioloop = IOLoop.instance()
ioloop = IOLoop.current()
for s in (signal.SIGINT, signal.SIGTERM):
signal.signal(s, shutdown_handler)
ioloop.start()
Expand Down
4 changes: 2 additions & 2 deletions zerver/lib/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _on_connection_open_error(
"TornadoQueueClient couldn't connect to RabbitMQ, retrying in %d secs...",
retry_secs,
)
ioloop.IOLoop.instance().call_later(retry_secs, self._reconnect)
ioloop.IOLoop.current().call_later(retry_secs, self._reconnect)

def _on_connection_closed(
self, connection: pika.connection.Connection, reason: Exception
Expand All @@ -313,7 +313,7 @@ def _on_connection_closed(
"TornadoQueueClient lost connection to RabbitMQ, reconnecting in %d secs...",
retry_secs,
)
ioloop.IOLoop.instance().call_later(retry_secs, self._reconnect)
ioloop.IOLoop.current().call_later(retry_secs, self._reconnect)

def _on_open(self, connection: pika.connection.Connection) -> None:
assert self.connection is not None
Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/runtornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def inner_run() -> None:
add_client_gc_hook(missedmessage_hook)
setup_tornado_rabbitmq()

instance = ioloop.IOLoop.instance()
instance = ioloop.IOLoop.current()
instance.start()
except KeyboardInterrupt:
# Monkey patch tornado.autoreload to prevent it from continuing
Expand Down
8 changes: 4 additions & 4 deletions zerver/tornado/event_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def timeout_callback() -> None:
heartbeat_event = create_heartbeat_event()
self.add_event(heartbeat_event)

ioloop = tornado.ioloop.IOLoop.instance()
ioloop = tornado.ioloop.IOLoop.current()
interval = HEARTBEAT_MIN_FREQ_SECS + random.randint(0, 10)
if self.client_type_name != "API: heartbeat test":
self._timeout_handle = ioloop.call_later(interval, timeout_callback)
Expand All @@ -269,7 +269,7 @@ def disconnect_handler(self, client_closed: bool = False) -> None:
self.current_handler_id = None
self.current_client_name = None
if self._timeout_handle is not None:
ioloop = tornado.ioloop.IOLoop.instance()
ioloop = tornado.ioloop.IOLoop.current()
ioloop.remove_timeout(self._timeout_handle)
self._timeout_handle = None

Expand Down Expand Up @@ -607,12 +607,12 @@ def send_restart_events(immediate: bool = False) -> None:
def handle_sigterm(server: tornado.httpserver.HTTPServer) -> NoReturn:
logging.warning("Got SIGTERM, shutting down...")
server.stop()
tornado.ioloop.IOLoop.instance().stop()
tornado.ioloop.IOLoop.current().stop()
sys.exit(1)


def setup_event_queue(server: tornado.httpserver.HTTPServer, port: int) -> None:
ioloop = tornado.ioloop.IOLoop.instance()
ioloop = tornado.ioloop.IOLoop.current()

if not settings.TEST_SUITE:
load_event_queues(port)
Expand Down

0 comments on commit a9472c2

Please sign in to comment.