By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,533 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,533 IT Pros & Developers. It's quick & easy.

Weird platform dependent error: Using pty.fork()

P: n/a
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

Jul 14 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.