Skip to content

Commit

Permalink
Merge pull request #2363 from zauberzeug/cpu_bound
Browse files Browse the repository at this point in the history
add explanation for run.cpu_bound
  • Loading branch information
falkoschindler authored Jan 12, 2024
2 parents 20962e4 + 906ef25 commit c371fff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nicegui/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit c371fff

Please sign in to comment.