Browse Source

Ignore `CancelledError` in `check_for_late_return_value` (#3296)

* ignore CancelledError in check_for_late_return_value

* tiny simplification for consistency with other try-except blocks
Falko Schindler 11 months ago
parent
commit
941aa87804
2 changed files with 7 additions and 3 deletions
  1. 6 2
      nicegui/page.py
  2. 1 1
      nicegui/run.py

+ 6 - 2
nicegui/page.py

@@ -94,8 +94,12 @@ class page:
         parameters_of_decorated_func = list(inspect.signature(func).parameters.keys())
 
         def check_for_late_return_value(task: asyncio.Task) -> None:
-            if task.result() is not None:
-                log.error(f'ignoring {task.result()}; it was returned after the HTML had been delivered to the client')
+            try:
+                if task.result() is not None:
+                    log.error(f'ignoring {task.result()}; '
+                              'it was returned after the HTML had been delivered to the client')
+            except asyncio.CancelledError:
+                pass
 
         @wraps(func)
         async def decorated(*dec_args, **dec_kwargs) -> Response:

+ 1 - 1
nicegui/run.py

@@ -24,7 +24,7 @@ async def _run(executor: Any, callback: Callable[P, R], *args: P.args, **kwargs:
     except RuntimeError as e:
         if 'cannot schedule new futures after shutdown' not in str(e):
             raise
-    except asyncio.exceptions.CancelledError:
+    except asyncio.CancelledError:
         pass
     return  # type: ignore  # the assumption is that the user's code no longer cares about this value