By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

low level python read's

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.