problems with blocking pipes, threading

Donn Cave donn at u.washington.edu
Fri Jan 28 11:49:14 EST 2000


Quoth "Sven Drescher" <Sven.Drescher at dlr.de>:
| I'm on the way to implement a process manager to start and finish specific
| processes. I do that with fork and execv under Solaris and with Mark
| Hammond's win32 extensions under Windows NT. All starts and finishs correct.
| But if I try to redirect the childs stdout with a pipe and read it out
| parallel from parent, the read-function blocks until the child is killed.
| Here is a short example of my test programm. I don't know what's wrong. I
| tried two threads, but still blocking.

I'm on boggy ground here if we're talking about Windows NT.  One of
these days I'm going to have to wade in there.  But at least on UNIX,
this can be the fault of the other process.

Most programs write their output through a C library function like
printf().  Those functions can buffer output, for efficiency, and
unless the output device is a terminal or the programmer specifically
directs otherwise, they will.  So according to its logic, the program
may have written output, but some or all of that output may still be
in that process buffer, waiting to be flushed out by more writes or
by program exit.

If you want to see whether this is really the problem, you might
write a sample program like  sys.stdout.write('Hello\n'); time.sleep(1000.0)
and verify that its pipe blocks this way.  Then add sys.stdout.flush()
after the write, and see if anything is different.

Don't know anything about Solaris, either!  Threads are hairy.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu



More information about the Python-list mailing list