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

Non-Blocking IO

mp
I'm trying to use popen2 to call a program and then write and read
data from the program using a Python script. Unfortunately, my calls
to read block (I need non-blocking IO), and all the workarounds I've
seen online don't work. Here is my most promising solution and how it
breaks:

Source of solution: http://mail.python.org/pipermail/pyt...ch/052263.html
def
setblocking(fd,flag):
" set/clear blocking
mode"
# get the file's current flag
settings
fl = fcntl.fcntl(fd,
fcntl.F_GETFL)
if
flag:
# clear non-blocking mode from
flags
fl = fl &
~os.O_NONBLOCK

else:
# set non-blocking mode from
flags
fl = fl |
os.O_NONBLOCK
# update the file's
flags
fcntl.fcntl(fd, fcntl.F_SETFL,
fl)
def
try3():
fin,fout=
os.popen2("echo.py")

setblocking(fout.fileno(),False)

os.write(fin.fileno(),'blah')

fin.flush()
print os.read(fout.fileno(),256)

Calling try3() yields the error:
File "./test.py", line 54, in try3
print os.read(fout.fileno(),256)
OSError: [Errno 35] Resource temporarily unavailable

If anyone could help me accomplish this I'd be extremely grateful.
Thanks!
MP

Sep 1 '07 #1
2 6506
In message <11**********************@k79g2000hse.googlegroups .com>, mp
wrote:
Calling try3() yields the error:
File "./test.py", line 54, in try3
print os.read(fout.fileno(),256)
OSError: [Errno 35] Resource temporarily unavailable
That's what's supposed to happen. That's telling you there are no bytes
currently available to be read.
Sep 1 '07 #2
"mp" <mail....il.comwrote:

Calling try3() yields the error:
File "./test.py", line 54, in try3
print os.read(fout.fileno(),256)
OSError: [Errno 35] Resource temporarily unavailable
This means there is no data available- its actually working!

- Hendrik

Sep 1 '07 #3

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...

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.