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

ref: Remove usage of deprecated get_event_loop #4697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Nov 19, 2024

Remove usage of deprecated get_event_loop

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 19, 2024
Copy link

codspeed-hq bot commented Nov 19, 2024

CodSpeed Performance Report

Merging #4697 will improve performances by 56.75%

Comparing cbornet:run-until-complete (b84f3c6) with main (7614cfb)

Summary

⚡ 2 improvements
✅ 13 untouched benchmarks

Benchmarks breakdown

Benchmark main cbornet:run-until-complete Change
test_successful_run_with_input_type_any 220.6 ms 140.7 ms +56.75%
test_successful_run_with_output_type_debug 247.6 ms 216.9 ms +14.17%

if loop.is_running():
# Run the coroutine in a separate event loop in a new thread
return run_in_thread(coro)
return loop.run_until_complete(coro)
Copy link
Collaborator Author

@cbornet cbornet Nov 19, 2024

Choose a reason for hiding this comment

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

If the loop is not running, this will most probably not work.



def run_until_complete(coro):
try:
loop = asyncio.get_event_loop()
if loop.is_running():
# Run the coroutine in a separate event loop in a new thread
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What is the advantage of running in a separate thread+loop ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't remember. Maybe related to the this event loop is already running error.

Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

LGTM. We should probably add tests.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants