473,378 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Weird platform dependent error: Using pty.fork()

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
0 1337

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: prabu | last post by:
Hello Experts, I am using a HP B.11.11 U 9000/800 machine,I want to learn Python.I have python (2.3.3) installed in it. When I excute python,got the following error,how to correct it?. # python...
10
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << "...
2
by: James Aguilar | last post by:
There is a syntax error in this code that I can't figure out. template <class T> std::ostream &operator <<(std::ostream &os, PriorityQueue<T> &q) { using namespace std; //g++ doesn't like...
8
by: aling | last post by:
Given the bit field struct: int main() { union { struct { unsigned short s1 : 4; unsigned short s2 : 3;
12
by: Yarco | last post by:
when doing fork in a loop: while(1) { tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len); if (tmp_sd == -1) { perror("accept"); exit(0); } //check client ip
0
by: pythonhelpneeded | last post by:
While building Python 2.4.3 on SCO OpenServer 5.0.5, I'm getting the error below. The modules mentioned seem to be available in the Lib subdirectory. I've tried setting PYTHONHOME to the build...
1
by: /M | last post by:
Hi! As you know, one way to seperate platform dependent code from platform _independent_ code is to create an abstract base class which acts as an interface towards all platform independent code...
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
3
by: saneman | last post by:
I have read that Python is a platform independent language. But on this page: http://docs.python.org/tut/node4.html#SECTION004220000000000000000 it seems that making a python script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.