Closing pipes

Donn Cave donn at drizzle.com
Sun Mar 16 05:04:21 CET 2003


Quoth Tom Chance <tomchance at gmx.net>:
| I've got a bit of code that opens a new pipe with os.popen, to start
| mencoder. When I call the close() function on it, it takes an unacceptably
| long time to close the pipe and return to the main thread.
|
| I've tried using popen2.popen2 to open and close the thread, and this will
| close the thread instantly, but rather than killing the process, it simply
| seems to detach itself from the thread and return python to its main
| thread.
|
| Is it simply an unavoidable feature of python and its pipe support that it
| will take quite a while to kill a process? Is there any way I can kill the
| process more quickly?

You would kill the process with the kill() function (posix or os.kill())
It sends your choice of signal to the process;  you might use SIGTERM.

The close() function for your popen file object is actually calling
pclose(3), which waits for the process to exit and returns its exit
status.  (Though you get that exit status only if it's non-zero -
for some reason, the Python version substitutes None for 0.)

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list