Force streamlit to use all the cpus available

Hi,

I have developed a streamlit app that runs in a docker container on a server with 5 cpus. After some investigation I found out that the app only uses one cpu at the time (and actually maxes out when running heavy computations). It’s clearly not taking advantage of the 4 other cpus available and I was wondering if there was an easy (or complicated) way to force streamlit to run the computation on multiple cpus. I was hoping that some sort of automatic load balancing would happen but that’s clearly not the case.

What are my options here?

Thanks

Hi @fdubinski -

This is really a Python limitation, not really a Streamlit one. Python for historical reasons runs primarily single-threaded per process, unless a specific Python package uses Cython or another compiled language to avoid the Global Interpreter Lock (GIL).

There are ways to have things running across multiple cores, such as using certain libraries as mentioned above, or multiprocessing module in Python, or writing your own threaded code, but there aren’t a lot of “free” ways to achieve parallelism in Python.

1 Like