Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: spawn or thread for long running background process?

I am planning to make a long running background process with Python but I am still unsure whether to use os.spawnle or thread. I've only read about it therefore I have not much experience with either spawn or thread. Is there any rule of thumb when to use which?

Thanks heaps

like image 517
Joshua Partogi Avatar asked Apr 20 '26 02:04

Joshua Partogi


1 Answers

Be sure that you take the Global Interpreter Lock into account. If the long running process is CPU intensive, you should probably make it an independent process. If on the other hand, it's going to spend a lot of time blocking, then the GIL isn't really that big of a deal and you should be fine to make it a thread.

Also, if you don't need something in particular that os.spawnle provides, consider using the multiprocessing package from the standard library. It provides an interface similar to that of the threading package and is altogether easier to use than mucking around with manually spawning and tracking processes.

like image 142
aaronasterling Avatar answered Apr 21 '26 15:04

aaronasterling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!