浏览代码

handle exception in async event callback in the right context (fixes #1370)

Falko Schindler 1 年之前
父节点
当前提交
9a4082ba0b
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      nicegui/events.py

+ 4 - 1
nicegui/events.py

@@ -309,7 +309,10 @@ def handle_event(handler: Optional[Callable[..., Any]], arguments: EventArgument
         if isinstance(result, Awaitable):
             async def wait_for_result():
                 with parent_slot:
-                    await result
+                    try:
+                        await result
+                    except Exception as e:
+                        globals.handle_exception(e)
             if globals.loop and globals.loop.is_running():
                 background_tasks.create(wait_for_result(), name=str(handler))
             else: