I have been trying to write a simple python application to implement a worker queue
every webpage I found about threading has some random guy commenting on it, you shouldn’t use python threading because this or that, can someone help me out? what is up with Python threading, can I use it or not? if yes which lib? the standard one is good enough?
I have been trying to write a simple python application to implement a worker
Share
Python’s threads are perfectly viable and useful for many tasks. Since they’re implemented with native OS threads, they allow executing blocking system calls and keep “running” simultaneously – by calling the blocking syscall in a separate thread. This is very useful for programs that have to do multiple things at the same time (i.e. GUIs and other event loops) and can even improve performance for IO bound tasks (such as web-scraping).
However, due to the Global Interpreter Lock, which precludes the Python interpreter of actually running more than a single thread simultaneously, if you expect to distribute CPU-intensive code over several CPU cores with threads and improve performance this way, you’re out of luck. You can do it with the
multiprocessingmodule, however, which provides an interface similar tothreadingand distributes work using processes rather than threads.I should also add that C extensions are not required to be bound by the GIL and many do release it, so C extensions can employ multiple cores by using threads.
So, it all depends on what exactly you need to do.