Răsfoiți Sursa

add explanation for run.cpu_bound

Rodja Trappe 1 an în urmă
părinte
comite
906ef255a5
1 a modificat fișierele cu 7 adăugiri și 1 ștergeri
  1. 7 1
      nicegui/run.py

+ 7 - 1
nicegui/run.py

@@ -24,7 +24,13 @@ async def _run(executor: Any, callback: Callable, *args: Any, **kwargs: Any) ->
 
 
 async def cpu_bound(callback: Callable, *args: Any, **kwargs: Any) -> Any:
-    """Run a CPU-bound function in a separate process."""
+    """Run a CPU-bound function in a separate process.
+
+    `run.cpu_bound` needs to execute the function in a separate process.
+    For this it needs to transfer the whole state of the passed function to the process (which is done with pickle).
+    It is encouraged to create static methods (or free functions) which get all the data as simple parameters (eg. no class/ui logic)
+    and return the result (instead of writing it in class properties or global variables).
+    """
     return await _run(process_pool, callback, *args, **kwargs)