Search code examples
pythonmultithreadingmultiprocessinggil

Using the GIL as a thread pool


Note: My education on this topic is lacking, so I may be making some naive assumptions.

Assume you have a function performing blocking I/O. You need to run this function n times.

If you were to simply spawn n threads (using the threading module) and start them at the same time, would it work to simply use the GIL to manage the threads (based on I/O) as opposed to using the multiprocessing.pool module to manage subprocesses?


Solution

  • It's bad practice to use an implementation detail as a core feature of your code. The GIL is an implementation detail of CPython, and doesn't exist in other implementations.

    Use things that are designed to do what you want.