Clueless: piping between 2 non-python processes
Donn Cave
donn at drizzle.com
Sun Oct 26 14:18:41 EST 2003
More information about the Python-list mailing list
Sun Oct 26 14:18:41 EST 2003
- Previous message (by thread): Clueless: piping between 2 non-python processes
- Next message (by thread): Clueless: piping between 2 non-python processes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Quoth Michael Lehmeier <m_lehmeier at gmx.de>: ... | This is what I have here now: | | # Wait for B to terminate | os.waitpid(pidB, os.WNOHANG) | | # Kill A (even if it has finished already... this might need a | # try/except) | print "Terminating A" | os.kill(pidA, signal.SIGKILL) | | # Wait for A (to avoid zombies) | os.waitpid(pidA, os.WNOHANG) | | print "Terminating B" | os.kill(pidA, signal.SIGKILL) I may be losing track of where we are. The way I remember it, you expect A to complete on its own, and the objective was to kill B then, if necessary. (The ideal solution, of course, would be to fix B so that doesn't need that.) But that's not at all what you're doing here. In fact you never do kill B, though it appears that in the last line you meant to. I suggested that you wait for B, with WNOHANG, because you can expect a brief lag between A's exit and B's exit, if B will exit as it should when it detects end of file on the input unit. There are tricky ways to use extraneous pipes with select for things like this, but the simple route is to check (hence WNOHANG), sleep a little, check, sleep, etc. for as long as you think is appropriate. Then kill him. But first, wait for A, without WNOHANG. | If I understand it correctly, since B or A seem to take some time | starting up, waitpid ignores them because of WNOHANG. | That makes this waitpid pretty useless, doesn't it? Yes. This will all be pretty easy to write if you think about what you want it to do. It may help to draw a diagram of the course of A and B's lifetimes, as you expect them to work, and then write the code that follows from that. | What about the Popen3 approach? | Wouldn't it be cleaner (once I get it running)? I'm sorry, I didn't look very hard at your Popen3 post, but I assume you mean to have the Python parent process shovel data between A and B. This doubles the I/O, when the parent could be sleeping quietly and just waiting for the process to exit. By the time you get it working, I find it hard to imagine that it will be cleaner by any standard, but then I can't be sure what you mean by clean. Donn Cave, donn at drizzle.com
- Previous message (by thread): Clueless: piping between 2 non-python processes
- Next message (by thread): Clueless: piping between 2 non-python processes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list