pkg.lib.App: Fix event loop for Python 3.14+ #59

Merged
Jan Lindemann merged 1 commit from jan/feature/20260814-pkg-lib-app-fix-event-loop-for-python into master 2026-08-14 23:03:04 +02:00 AGit

pkg.lib.App: Fix event loop for Python 3.14+

asyncio.get_event_loop() is removed in Python 3.14 when called from outside an async context. The current code calls it in init(), which crashes on 3.14+.

To fix this, drop the eager loop creation from init(). Instead, lazily create a loop in run() via asyncio.new_event_loop() when no external loop was provided, and close it in the finally block. This makes the lifecycle symmetric: run() owns the full create-use-close cycle and supports re-entrant calls.

Replace del() with an explicit close() method, guarding against double-close via is_closed(). close() always clears __eloop to None so a closed loop never lingers.

#### pkg.lib.App: Fix event loop for Python 3.14+ asyncio.get_event_loop() is removed in Python 3.14 when called from outside an async context. The current code calls it in __init__(), which crashes on 3.14+. To fix this, drop the eager loop creation from __init__(). Instead, lazily create a loop in run() via asyncio.new_event_loop() when no external loop was provided, and close it in the finally block. This makes the lifecycle symmetric: run() owns the full create-use-close cycle and supports re-entrant calls. Replace __del__() with an explicit close() method, guarding against double-close via is_closed(). close() always clears __eloop to None so a closed loop never lingers.
pkg.lib.App: Fix event loop for Python 3.14+
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m36s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m24s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m17s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m18s
CI / Packaging test (push) Successful in 0s
25fc4d89f7
asyncio.get_event_loop() is removed in Python 3.14 when called from
outside an async context. The current code calls it in __init__(),
which crashes on 3.14+.

To fix this, drop the eager loop creation from __init__(). Instead,
lazily create a loop in run() via asyncio.new_event_loop() when no
external loop was provided, and close it in the finally block. This
makes the lifecycle symmetric: run() owns the full create-use-close
cycle and supports re-entrant calls.

Replace __del__() with an explicit close() method, guarding against
double-close via is_closed(). close() always clears __eloop to None
so a closed loop never lingers.

Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-08-14 22:54:00 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!59
No description provided.