Python: spwn or thread for a lengthy background process?

I plan to make a long background process with Python, but I'm still not sure whether to use os.spawnleor thread. I just read about it, so I do not have much experience with either generation or flow. Is there any rule of thumb when to use which?

Thanks heaps

+3
source share
2 answers

Make sure you take Global Interpreter Lock . If a lengthy workflow has processor intensity, you should probably make it an independent process. If, on the other hand, it is going to spend a lot of time locking, then the GIL is actually not that big, and you should be fine to make it a thread.

In addition, if you do not need something special that os.spawnleprovides, consider using the multiprocessing package from the standard library. It provides an interface similar to the threading interface and is generally easier to use than spoofing with spawning and tracking processes manually.

+4
source

, os.spawnle , , , . , - - , , - os.spawnle ( ); .

, , v., , , . , , /, , - , , , .

+2

Source: https://habr.com/ru/post/1764784/


All Articles