low level python read's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gz

    #1

    low level python read's

    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_R DWR);
    read(f,buffer,1 000);

    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"?

  • Marc 'BlackJack' Rintsch

    #2
    Re: low level python read's

    In <1168184689.924 811.305290@42g2 000cwt.googlegr oups.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

    Comment

    Working...