0

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
LarsVegas
  • 6,522
  • 10
  • 43
  • 67

2 Answers2

1

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.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

system() is a combine of fork() + exec() + waitpid(). You should not call waitpid() again.

lqs
  • 1,434
  • 11
  • 20