Threads vs subprocesses

John O'Hagan research at johnohagan.com
Fri Jun 15 09:49:09 EDT 2012


I have a program in which the main thread launches a number of CPU-intensive
worker threads. For each worker thread two python subprocesses are started,
each of which runs in its own terminal: one displays output received from the
worker thread via a socket, the other takes text input to control the thread
(this is done by having another thread receive the input via a socket and write
to the worker thread's arguments).

So far so good, but it occurred to me that instead of launching all these
worker threads, I could just put their target code in separate executable
files and launch them as subprocesses. That way there would be fewer threads,
but each subprocess would be doing more work. 

My question is, on a single core machine, what are the pros and cons of
threads vs subprocesses in a setup like this? 

Thanks,

John



More information about the Python-list mailing list