Skip to content

Commit afc98d3

Browse files
authored
Avoid poll(None) if no timeout specified (#622)
Resolves issue #583
1 parent 73b7b71 commit afc98d3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
python-ev3dev2 (2.0.0~beta4) UNRELEASED; urgency=medium
22

33
[Daniel Walton]
4+
* Avoid race condition due to poll(None)
45
* MoveDifferential odometry support, tracks robot's (x,y) position
56
* Display support via raspberry pi HDMI
67
* Update tests/README to include sphinx-build instructions

ev3dev2/motor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,14 +865,23 @@ def wait(self, cond, timeout=None):
865865
self._poll = select.poll()
866866
self._poll.register(self._state, select.POLLPRI)
867867

868+
# Set poll timeout to something small. For more details, see
869+
# https://github.com/ev3dev/ev3dev-lang-python/issues/583
870+
if timeout:
871+
poll_tm = min(timeout, 100)
872+
else:
873+
poll_tm = 100
874+
868875
while True:
876+
# This check is now done every poll_tm even if poll has nothing to report:
869877
if cond(self.state):
870878
return True
871879

872-
self._poll.poll(None if timeout is None else timeout)
880+
self._poll.poll(poll_tm)
873881

874882
if timeout is not None and time.time() >= tic + timeout / 1000:
875-
return False
883+
# Final check when user timeout is reached
884+
return cond(self.state)
876885

877886
def wait_until_not_moving(self, timeout=None):
878887
"""

0 commit comments

Comments
 (0)