문제

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