Should worker do better than asyncio.to_thread()?
#2424
-
|
I use Pyodide both in main thread and in a worker. As far as I understand, worker is a proper Web way to perform heavy calculations (I do processing of large images with Pillow/NumPy) without blocking main thread. I invested some effort into creating a worker, it was not easy, and it turned out that things don't run noticeably faster than without a worker. Also, when non-NumPy, GIL-holding code like I'm a Python guy, not a Web/JS guy, so I could easily miss something important. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
it's literally: <script type="py" src="./your_code.py" worker></script>what was difficult?
without any code or minimal reproducible example, it's hard to guess/help but I believe you are resizing via DOM elements? I can write a
usually the ideal scenario is MicroPython on the main thread for fast bootstrap and Pyodide workers. If you name your workers you can reach their exported features/utilities via the dedicated API. See the second part of the docs: https://docs.pyscript.net/2025.11.2/user-guide/workers/#worker-interactions edit the other possibility is that you have a single thread environment so everything computes on the same CPU and workers can't do magic |
Beta Was this translation helpful? Give feedback.
it's literally:
what was difficult?
without any code or minimal reproducible example, it's hard to guess/help but I believe you are resizing via DOM elements?
I can write a
while True: passloop in a worker and the main thread would always be responsive so I am pretty sure you are not using a worker or not computing within the worker.usually the ideal scenario is MicroPython on the main thread for fast bootstrap and Pyodide workers. If y…