Proccess termination

A

alexrait1

I use popen.popen2 or popen.popen3 to start a new process and read from
it's stdout/ write to it's stdin.
But I need a way to know when a process terminates. If it closes it's
stdin/stdout, it doesn't mean it has really terminated...
And if possible, I would like to see an exception thrown when that
happens..
Do you know about a library that provides these tools other then the
standard os module... or should I use it otherwise?

Thanx Alex Rait.
 
D

Diez B. Roggisch

alexrait1 said:
I use popen.popen2 or popen.popen3 to start a new process and read from
it's stdout/ write to it's stdin.
But I need a way to know when a process terminates. If it closes it's
stdin/stdout, it doesn't mean it has really terminated...

You can use the Popen-objects pid to see if a process still runs.
And if possible, I would like to see an exception thrown when that
happens..

Not possible - that exception would be asynchronous to your program flow.
The only thing I can think of that would make this possible is to have a
second thread waiting for process termination - and sending the own process
a signal. If I'm not mistaken, that will be propagated to the main thread.

All this is meant to be running on unix - not sure how thinks work out on
windows.
 
G

George Yoshida

alexrait1 said:
I use popen.popen2 or popen.popen3 to start a new process and read from
it's stdout/ write to it's stdin.
But I need a way to know when a process terminates.
Do you know about a library that provides these tools other then the
standard os module... or should I use it otherwise?

popen2.Popen3, popen2.Popen4 and subprosess.Popen have poll/wait methods.

These will do what you're looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top