Skip to content

Fix warning about asyncio.get_event_loop() in Python 3.12 #1071

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

Merged
merged 2 commits into from
Jun 5, 2025

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Jun 4, 2025

In Python 3.12, the code in shell_tools.py produces the following warnings when running check/pytest:

dev_tools/shell_tools_test.py::test_run_cmd_raise_on_fail
dev_tools/shell_tools.py:185:
DeprecationWarning: There is no current event loop
result = asyncio.get_event_loop().run_until_complete(

The fix involves managing the event loop. The updated functions now try to get the current running event loop; if no loop is running, they create a new one, use it, and then close it.

Note: commit c3ab0fa has the actual code changes. Commit ba775f5 contains purely formatting changes from applying check/format-incremental.

mhucka added 2 commits June 4, 2025 18:45
In Python 3.12, the code in `shell_tools.py` produces the following
warnings when running `check/pytest`:

```
dev_tools/shell_tools_test.py::test_run_cmd_raise_on_fail
dev_tools/shell_tools.py:185:
DeprecationWarning: There is no current event loop
result = asyncio.get_event_loop().run_until_complete(
```

The fix involves managing the event loop. The updated functions now
try to get the current running event loop; if no loop is running, they
create a new one, use it, and then close it.
@mhucka mhucka requested review from pavoljuhas and dstrain115 June 4, 2025 19:44
@mhucka mhucka self-assigned this Jun 4, 2025
@mhucka mhucka requested a review from fdmalone June 5, 2025 04:22
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

lgtm

@mhucka mhucka added this pull request to the merge queue Jun 5, 2025
Merged via the queue into master with commit a941cfb Jun 5, 2025
29 checks passed
@mhucka mhucka deleted the mh-fix-py312-asyncio-warning branch June 5, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants