Weird platform dependent error: Using pty.fork()

spacelabstudio at gmail.com spacelabstudio at gmail.com
Fri Jul 14 11:30:16 EDT 2006


Hi, I'm observing some weird behavior and have written the following
test program to demonstrate.  This works under cygwin/WinXP but not
Gentoo(kernel 2.6):

huh.py
-------------------------------------------
import pty,os,sys

# Fork
( pid, fd ) = pty.fork()

if pid == 0:
    # Child thread
    print 'Have a happy day!'
    print 'Forza Azzurri!'

else:
    # Controlling process
    # read stdout from child process
    # and send to stderr
    stream = os.fdopen( fd )
    line = stream.readline()
    while len( line ) > 0:
        sys.stderr.write(line)
        line = stream.readline()
    stream.close()
-------------------------------------------

This program runs perfectly under cygwin on Windows XP using python
2.4.3:

========================================================================
crossi at 6M0D481 ~/proj/plum
$ python huh.py
Have a happy day!
Forza Azzurri!

crossi at 6M0D481 ~/proj/plum
$ python huh.py 2>/dev/null

crossi at 6M0D481 ~/proj/plum
$ python
Python 2.4.3 (#1, May 18 2006, 07:40:45)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

crossi at 6M0D481 ~/proj/plum
$
========================================================================

But on Gentoo (2.6 kernel) with Python 2.4.3 it dies with an I/O error
when it hits the end of the stream:

========================================================================
chris at jupiter ~/proj/plum $ python huh.py
Have a happy day!
Forza Azzurri!
Traceback (most recent call last):
  File "huh.py", line 19, in ?
    line = stream.readline()
IOError: [Errno 5] Input/output error
chris at jupiter ~/proj/plum $ python huh.py 2>/dev/null
chris at jupiter ~/proj/plum $ python
Python 2.4.3 (#1, Jul 13 2006, 23:02:30)
[GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
========================================================================

Anybody have any idea what's going on here?  Is there a better way to
fork and capture the output of the child process?

Thanks,
Chris




More information about the Python-list mailing list