Skip to content

file handle cache breaks sensors #67

Closed

Description

@ensonic

try this in python (with sensor 0 being the touch sensor):

f = open("/sys/class/lego-sensor/sensor0/value0", "r")
print f.readline()
0

f.seek(0)
print f.readline()
0

Activity

  1. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    Found a fix. PR is coming in a sec. But in the long run I think we should mmap these files.

  2. dlech commented on Nov 5, 2015

    @dlech
    Member

    There is no guarantee that the value returned by the sysfs attribute includes a newline, it is just convention.

    I think instead of flushing, it might be more efficient to open with no buffering.

    f = open("/sys/class/lego-sensor/sensor0/value0", "r", 0)
    

    These files can't be mmapped (except the bin_data attribute).

  3. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    I wonder if replacing readline with read would also solve this. readline-based implementation was only introduced recently. Will try to reproduce in a couple of hours.

  4. dlech commented on Nov 5, 2015

    @dlech
    Member

    I know from experience that you need to turn off buffering or read() does not work correctly.

  5. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    Good to know. I'll do a PR after some testing then.

  6. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    The flush() is better than nothing, but I can try differently. @ddemidov no need for another PR I can change this one.

  7. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    @ensonic, ok, thanks!

  8. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    PR updated using with with buffering disabled and using read()

  9. rhempel commented on Nov 6, 2015

    @rhempel
    Member

    Agreed, I merged the PR, if this fixes your issue, please close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions