Pipe IO Problem?

Donn Cave donn at u.washington.edu
Tue Sep 7 14:00:22 EDT 2004


In article <A5X_c.5607$wF4.1948 at trndny09>,
 "Chris S." <chrisks at NOSPAM.udel.edu> wrote:

> A wrote a small class to handle IO through pipes, but the connection 
> only seems to work in one direction. The following code defines 
> connection.py, engine.py, and controller.py. Once connected, the engine 
> is only able to send and the controller recieve. Also, this only works 
> when using popen2.popen3. Using os.popen3 doesn't work at all and seems 
> to behave completely differently.

I'm too lazy to track down the problem in your code, but
os.popen3 vs. popen2.popen3 is an easy one.  You can see
the code yourself, in the os.py module --

  def popen3(cmd, mode="t", bufsize=-1):
      import popen2
      stdout, stdin, stderr = popen2.popen3(cmd, bufsize)
      return stdin, stdout, stderr

Note different return value.

You can avoid some confounding factors, and possibly the
need for a separate thread, if you use the UNIX file descriptors
(e.g., outpfd = outp.fileno(), os.write(outpfd, string + '\n'),
etc.  The thread could go away if select() turns out to be suitable
for your application.  The buffering you get with file objects
is relatively useless here and likely not worth the trouble it causes.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list