lib.App: Restore caller's event loop in run()
run() remembers the thread's current event loop before creating a new one only when the app does not own a loop yet. The finally block, however, always restores the remembered loop or unsets the loop when there was none. So when a caller passes its own event loop to the App constructor and has set it as the thread's current loop, run() unsets the thread's loop on the way out, although it never changed it. Remember the thread's current event loop unconditionally and restore it in the finally block; for a caller-provided loop that is a no-op. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
b78d922f0a
commit
8f52639d14
1 changed files with 1 additions and 2 deletions
|
|
@ -513,9 +513,8 @@ class App: # export
|
||||||
return self.__parser
|
return self.__parser
|
||||||
|
|
||||||
def run(self, argv: list[str] | None = None) -> None:
|
def run(self, argv: list[str] | None = None) -> None:
|
||||||
previous_eloop: asyncio.AbstractEventLoop | None = None
|
previous_eloop = _get_current_event_loop()
|
||||||
if self.__eloop is None:
|
if self.__eloop is None:
|
||||||
previous_eloop = _get_current_event_loop()
|
|
||||||
eloop = asyncio.new_event_loop()
|
eloop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(eloop)
|
asyncio.set_event_loop(eloop)
|
||||||
self.__eloop = eloop
|
self.__eloop = eloop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue