Reputation: 6832
I try to come up with a workaround for this python bug calling subprocess
. I figured the way to go is using os.system
in combination with os.waitpid
. To test this I wrote the code below. system_call_test.py
writes the pid
and lot's of text to the file f
. But calling os.waitpid()
always get me this error: OSError: [Errno 10] No child processes
. So I'm having a hard time to check if this construct is working properly. How can I ensure that the script waits for the termination of the other. I'm on windows XP/ python 2.7.
import os
f = r'D:\temp\called.txt'
s = os.system('C:\Python27\python.exe D:\python_spullen\system_call_test.py')
with open(f, 'r') as f_in:
i = f_in.readline()[-4:]
print i
rr = os.waitpid(int(i),0)
print rr
Upvotes: 0
Views: 1748
Reputation: 1454
system()
is a combine of fork()
+ exec()
+ waitpid()
. You should not call waitpid()
again.
Upvotes: 1
Reputation: 272417
os.system
returns the exit code of the process. So s
above is already populated and the process has exited. os.waitpid
has nothing to wait on.
Upvotes: 1