浏览代码

note about run.cpu_bound problem with classes

Rodja Trappe 1 年之前
父节点
当前提交
fc5bd3cd29
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      website/documentation/content/section_action_events.py

+ 3 - 0
website/documentation/content/section_action_events.py

@@ -71,6 +71,9 @@ doc.intro(generic_events_documentation)
     NiceGUI provides a `cpu_bound` function for running CPU-bound tasks in a separate process.
     NiceGUI provides a `cpu_bound` function for running CPU-bound tasks in a separate process.
     This is useful for long-running computations that would otherwise block the event loop and make the UI unresponsive.
     This is useful for long-running computations that would otherwise block the event loop and make the UI unresponsive.
     The function returns a future that can be awaited.
     The function returns a future that can be awaited.
+    NOTE: The function 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).
 ''')
 ''')
 def cpu_bound_demo():
 def cpu_bound_demo():
     import time
     import time