471,330 Members | 1,039 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 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 6406
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by lothar | last post: by
25 posts views Thread by Yves Glodt | last post: by
32 posts views Thread by Adrian Herscu | last post: by
8 posts views Thread by Bern McCarty | last post: by
14 posts views Thread by Patrick Kowalzick | last post: by
399 posts views Thread by =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post: by

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.