-
Notifications
You must be signed in to change notification settings - Fork 453
fix(batch): replace asyncio.get_event_loop() with future-compatible implementation for Python 3.12+ #7440
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
base: develop
Are you sure you want to change the base?
Conversation
…mplementation for Python 3.12+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses deprecated asyncio API usage in the AsyncBatchProcessor to ensure compatibility with Python 3.12+ where asyncio.get_event_loop()
will raise RuntimeError when no event loop is running. The fix replaces the deprecated call with future-compatible logic using asyncio.get_running_loop()
and asyncio.new_event_loop()
.
- Replace deprecated
asyncio.get_event_loop()
with try/except pattern using modern asyncio APIs - Add comprehensive comments explaining Python version compatibility strategy
- Maintain backward compatibility while preparing for Python 3.14+ requirements
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
try: | ||
loop = asyncio.get_running_loop() | ||
except RuntimeError: | ||
# No running loop, create a new one for Lambda environment | ||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is incorrect. asyncio.get_running_loop()
is used to get an already running event loop, but in a Lambda environment without an active loop, you should directly create a new one. The correct approach is to use asyncio.get_event_loop()
replacement pattern with asyncio.new_event_loop()
and asyncio.set_event_loop()
or use asyncio.run()
for the coroutine execution.
Copilot uses AI. Check for mistakes.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @kattakaha! I left a small comment that probably we need to think a little bit more about this. I'm testing Python 3.14 to see if this is a problem.
try: | ||
loop = asyncio.get_running_loop() | ||
except RuntimeError: | ||
# No running loop, create a new one for Lambda environment | ||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code block is basically doing nothing with this try/except: trying to get a loop running or create a new one, but since Lambda doesn't have an active loop, it mostly falls into the "except" block, right? I haven't tested it yet, but I'm not sure if this is the correct implementation for it.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7440 +/- ##
===========================================
- Coverage 96.37% 96.34% -0.03%
===========================================
Files 275 275
Lines 13048 13052 +4
Branches 974 974
===========================================
Hits 12575 12575
- Misses 366 370 +4
Partials 107 107 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Issue number: closes #7397
Summary
This PR addresses the tech debt noted in
AsyncBatchProcessor
regardingasyncio.get_event_loop()
potentially failing in Python 3.12+. The fix replaces the deprecatedasyncio.get_event_loop()
call with a future-compatible implementation that works across Python versions.Changes made
asyncio.get_event_loop()
with try/except logic usingasyncio.get_running_loop()
andasyncio.new_event_loop()
asyncio.get_event_loop()
raisesRuntimeError
User experience
RuntimeError
in Python 3.14+ Lambda environmentsBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.