Reputation: 418
I have a program I'm running within another. The parent program freezes up while the child process is running. Is there a way to run the child process in the OS as a parent process itself?
Upvotes: 2
Views: 9196
Reputation: 94881
You can use subprocess.Popen
, assuming you're really trying to launch a program that's completely separate from the parent Python script:
import subprocess
subprocess.Popen(["command", "-a", "arg1", "-b", "arg2"])
This will launch command
as a child process of the calling script, without blocking to wait for it to finish. If the parent exits, the child process will continue to run.
Upvotes: 5
Reputation: 23500
If you really want to have independent processes, please have a look at the multiprocessing
module. If it is enough to have a separate thread running in the same OS process, then use threading
. Or are you interested in starting an external program from within a Python script with subprocess
?
Unfortunately, the terminology is a bit confusing. For example, in Linux "thread" and "process" are both independent processes with no real difference. In python "process" is a separate OS precess, thread runs in the same OS process.
For more information on these, you might have a look at this question: Multiprocessing vs Threading Python
Upvotes: 0