"Ian Campbell" <ian-campb...@shaw.ca> wrote
I am trying to use this so maybe no one has to reply... sorry to inconvenience anyone.

No inconvenience and I'm glad you posted the solution you found.

That is pretty much what I had in mind but I didn't know you could get the _handle from the return value in Popen! That makes it much easier. I would still tend to run the execute and wait from a separate thread just in case...

def execute_and_wait(args, timeout=None):
   p = subprocess.Popen(args)
   if timeout:
       ret = WaitForSingleObject(p._handle, timeout)
       if ret==WAIT_TIMEOUT:
           TerminateProcess(p._handle, 1)
           return None
   return p.wait()

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to