subprocess seems to "detach" / ignore wait()

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Aug 20 16:22:30 EDT 2008


En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <gminick at bzt.bzt> escribió:

> On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
>
>>   child = Popen(cmd.split(), stderr=flog)
>>   print "Server running [PID %s]"%(child.pid)
>>   fpid.write(child.pid)
>
> I think that the problem here is that fpid.write() fails silently
> (probably TypeError), because it takes string as its first argument,
> not integer.

Exactly, but it doesn't fail "silently" (that would be a bug). The exception is raised, but due to the finally clause ending in sys.exit(0), it has no chance of being handled.
This is the original code, for reference:

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
  child = Popen(cmd.split(), stderr=flog)
  print "Server running [PID %s]"%(child.pid)
  fpid.write(child.pid)
  child.wait()
except KeyboardInterrupt:
  print "INT sent to vnc server"
finally:
  fpid.close()
  flog.close()
  os.remove(pidfile)
  os.remove(logfile)
  sys.exit(0)

-- 
Gabriel Genellina




More information about the Python-list mailing list