473,387 Members | 1,619 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,387 software developers and data experts.

slow non-blocking reads

hello all,

I am trying to fire up a child process using os.popen2, and have the
parent and child communicate in a non-blocking fashion. it works, but
somehow it's unbearably slow. the following simulates a blocking
readline:

import os, fcntl

fi, fo = os.popen2('./child')
fcntl.fcntl(fo.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)

def getline():
line = ''
while 1:
try:
line += os.read(fo.fileno(), 1)
if line.endswith('\n'):
return line
except OSError:
pass

print getline()

while 1:
fi.write('echo echo echo\n')
fi.flush()
print getline()

and this is the child process, written in C:

tcgetattr(0, &tty);
tty.c_lflag &= ~ICANON;
tty.c_cc[VTIME] = 0;
tty.c_cc[VMIN] = 0;
tcsetattr(0, TCSADRAIN, &tty);

fds[0].fd = 0;
fds[0].events = POLLIN;

fcntl(0, F_SETFL, O_NONBLOCK);

printf("start\n");
fflush(stdout);

while(1) {
if( poll(fds, 1, 0) > 0) {
if((fds[0].fd == 0) && (fds[0].revents & POLLIN)) {
read(0, &c, 1);

printf("%c", c);
fflush(stdout);
}
}
}

the child sends a 'start' message and then echoes the parent.

any thoughts about why this runs extremely slowly?
thanks!
mark dufour.
--
if vars: self.output('; '.join([self.type(var)+' '+name for (name,var)
in vars.items()])+';')
Jun 29 '06 #1
1 1075
In article <ma***************************************@python. org>,
"Mark Dufour" <ma*********@gmail.comwrote:
>any thoughts about why this runs extremely slowly?
Because both processes are chewing up most of your CPU each waiting for
the other to do something.
Jul 2 '06 #2

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

Similar topics

2
by: Tim Fountain | last post by:
We've recently enabled slow query logging on a server and it's proving interesting seeing which queries are bogging things down. This one is puzzling me a little: SELECT articleid, type,...
4
by: M Wells | last post by:
Hi All, I have a table that currently contains approx. 8 million records. I'm running a SELECT query against this table that in some circumstances is either very quick (ie results returned in...
7
by: Thomi Baechler | last post by:
Hello Everybody I run the following query against to identical databases. Execution time on the first DB is 0 seconds, on the other 6 seconds! SELECT dbo.HRMABZ.EMPKEY ,...
5
by: garydevstore | last post by:
Hi, I have a table defined as CREATE TABLE ( IDENTITY (1, 1) NOT NULL , NULL , NULL , NOT NULL , NULL , (255) COLLATE SQL_Latin1_General_CP1_CS_AS
9
by: SAL | last post by:
I have an ASP.NET 2.0 app that takes about 17 seconds to load on first startup but then is very fast after that. As I understand it from some posts in June, this is caused by the loading of the App...
13
by: eighthman11 | last post by:
using Access 2003 and sql server version 8.0 Hey everyone. Created a text box where the user types in an Inventory number and it takes them to that inventory number on the contimuous form. The...
10
by: kimiraikkonen | last post by:
Hi there, I figured out, for the first execution for any .NET-powered app such as VB.NET or C#, it takes 7-8 seconds to see main form of "any" application even the application consists of a single...
10
by: Arno R | last post by:
Hi all, So I bought a new laptop 10 days ago to test my apps with Vista. (home premium) Apparently Office 2007 is pre-installed. (a time limited but complete test version, no SP1) So I take the...
12
by: Marc Baker | last post by:
Bear with me here folks, I don't know much MS SQL performance. Wondering if someone can point me in the right direction. I have 1 particular database where queries are slow. To test this theory,...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.