Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no longer call set_event_loop in IOLoop.start() #3158

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions tornado/platform/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ def _atexit_callback() -> None:

atexit.register(_atexit_callback)

graingert marked this conversation as resolved.
Show resolved Hide resolved
if sys.version_info >= (3, 10):

def _get_event_loop() -> asyncio.AbstractEventLoop:
try:
return asyncio.get_running_loop()
except RuntimeError:
pass

return asyncio.get_event_loop_policy().get_event_loop()


else:
from asyncio import get_event_loop as _get_event_loop


class BaseAsyncIOLoop(IOLoop):
def initialize( # type: ignore
Expand Down Expand Up @@ -207,15 +193,7 @@ def _handle_events(self, fd: int, events: int) -> None:
handler_func(fileobj, events)

def start(self) -> None:
try:
old_loop = _get_event_loop()
except (RuntimeError, AssertionError):
old_loop = None # type: ignore
try:
asyncio.set_event_loop(self.asyncio_loop)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because asyncio.get_event_loop() calls asyncio.get_running_loop() this set_event_loop() is now redundant

self.asyncio_loop.run_forever()
finally:
asyncio.set_event_loop(old_loop)
self.asyncio_loop.run_forever()

def stop(self) -> None:
self.asyncio_loop.stop()
Expand Down