Weird platform dependent error: Using pty.fork()

S

spacelabstudio

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@6M0D481 ~/proj/plum
$ python huh.py
Have a happy day!
Forza Azzurri!

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

crossi@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@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@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@jupiter ~/proj/plum $ python huh.py 2>/dev/null
chris@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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top