469,336 Members | 5,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

low level python read's

gz
Hi!

I wanted to use python to test a simple character device (on linux) and
I'm running into strange behaviour of read..
I have a short buffer inside my device and the idea is that it blocks
read's when the buffer is empty. For reads that ask for more characters
that the buffer holds the device should return the number of bytes
actually read...

In c i can write:
f = open("/dev/testdevice",O_RDWR);
read(f,buffer,1000);

and i see in my device, that everything is ok.

No I'd love to reproduce this in python..
f = open("/dev/testdevice", "r+",0) # for unbuffered access
f.read(1000)

...but now i see in the device log's that python issued 2 reads! One
that got the whole buffer (less then 1000 chars) and after that python
tries to read more! (and hangs in my device, since the buffer is
empty...

So how do i stop python from trying to be smart and just read *at most*
1000 chars and let it go if he(it?*) reads less?

grzes.
p.s *is python a "he" or an "it"?

Jan 7 '07 #1
1 2091
In <11**********************@42g2000cwt.googlegroups. com>, gz wrote:
So how do i stop python from trying to be smart and just read *at most*
1000 chars and let it go if he(it?*) reads less?
For low level file stuff use the functions in the `os` module, i.e.
`os.read()`.
p.s *is python a "he" or an "it"?
I'd say "it".

Ciao,
Marc 'BlackJack' Rintsch

Jan 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Guettler | last post: by
3 posts views Thread by Phil Frost | last post: by
4 posts views Thread by Jeremy Sanders | last post: by
11 posts views Thread by Markus Breuer | last post: by
8 posts views Thread by York | last post: by
6 posts views Thread by George Sakkis | last post: by
6 posts views Thread by Maxim Veksler | last post: by
65 posts views Thread by Chris Carlen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.