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?

有帮助吗?

解决方案

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.

其他提示

How is the GIL even relevant here? What are you expecting to get out of it?

You can spawn n threads and have them all perform blocking I/O, without a GIL.

And if you want to "manage" the threads—e.g., join the all so you know when you're done—you still need to do that explicitly; the GIL doesn't help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top