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

Use old-style (3.5 ad 3.5) for asyncio.run #3065

Closed
wants to merge 1 commit into from
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
9 changes: 7 additions & 2 deletions lib/cylc/network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ async def async_request(self, command, args=None, timeout=None):
raise ClientError(response['error'])

def serial_request(self, command, args=None, timeout=None):
return asyncio.run(
self.async_request(command, args, timeout))
# TODO: replace by asyncio.run when minimum req is py37
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this todo because the asyncio.run actually does a bit more. It checks whether the loop created is the only one, as it is not expected to use one loop while there is already an asyncio loop in the same thread. It also collects events when debugging, and on shutdown of the loop tries to cancel any remaining futures enqueued. So not exactly the same as old code used to do, but same plus good improvements that would be nice for us to use too IMO.

loop = asyncio.new_event_loop()
try:
return loop.run_until_complete(
self.async_request(command, args, timeout))
finally:
loop.close()

__call__ = serial_request

Expand Down