Reputation: 12462
i have a daemon running which gets command and executes it by:
subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
I never do anything with it afterwards, no wait()
, no communicate()
is that okay to do so?
or are joining of the process required?
is there a similar thing to threading.deamon=True
for subprocess.Popen
?
Upvotes: 2
Views: 2825
Reputation: 17478
Since you set stdout=subprocess.PIPE, stderr=subprocess.PIPE
, and if you want to get the stdout, you can do this:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in p.stdout:
# do something here
#...
As you say the cmd
is executed as a daemon, I think daemon process should not be run in this way. Since once your python process exit with error, the daemon process would exited and your data will lost.
And if you run other process by subprocess.Popen(), such as mysql, linux comands etc, it is ok to do so. But you should know the process status(the return code), you should check the status of the process by call poll()
or wait()
. For more information, see docs of subproces.Popen.
Upvotes: 1