aws-powertools/powertools-lambda-python

Tech debt: Note about `asyncio.get_event_loop()` failling in Python 3.12+

Closed this issue · 7 comments

Why is this needed?

While perusing the code to understand how AsyncBatchProcessor starts the event loop, I found the following note in the code for BasePartialProcessor:

loop = asyncio.get_event_loop() # NOTE: this might return an error starting in Python 3.12 in a few years

Now that Lambda has the Python 3.13 runtime, this should probably re-evaluated to determine if any work is needed here to solve the concern or if the note can be removed.

Which area does this relate to?

Batch processing

Suggestion

Write a test to confirm whatever concern that prompted the note is or is not happening. If it happens, resolve the bug. If it doesn't happen, remove the note.

Acknowledgment

Hi @ryancausey, thanks for opening the issue.

Just to clarify, did you experience an error using that module with Python 3.12? Do you think we should remove the comment?

Thanks for opening this issue, @ryancausey! Since Python 3.12 (and in Python 3.13), the get_event_loop function raises a warning, but it still works for its intended purpose: to get the current event loop or create a new one and attach it to the current thread.

In Python 3.14, it throws an exception if the event loop doesn't exists. Since the Lambda runtime doesn't create an event loop it will likely fails, but I need to test. This is my radar when testing Python 3.14 and a good opportunity to create a end2end test for it.

Thanks again for pointing this out and helping us stay on top of critical changes. I really appreciate this.

Adding this to the backlog.

@dreamorosi to answer your question: No, I haven't encountered any problems using the AsyncBatchProcessor in my Python 3.13 lambda, though I admittedly just developed it yesterday. It sounds like @leandrodamascena has identified a breaking Python change in 3.14 that will cause this to stop working though.

Perfect, thanks again for reporting it!

Hi @ryancausey, I can confirm this is a bug affecting Python 3.14+. The fix is ​​simple, without any performance regressions, and I'll be opening a PR to fix it. Unfortunately, our unit/functional tests aren't catching this because they don't run in the Lambda environment, but I'll create an e2e test right after the Lambda team officially releases this version.

Thanks a lot for reporting this.

Warning

This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

This is now released under 3.22.1 version!