Skip to content

Threading error when 2 Threads may control the same Motor. Errors encountered in EV3Dev2 with different error messages on MicroPython vs Python3. No such errors encountered in EV3Dev(1) and PyBricks. #750

Open
@AntoniLuongPham

Description

@AntoniLuongPham

ev3dev version: 4.14.117-ev3dev-2.3.5-ev3

  • ev3dev-lang-python version:
    ||/ Name Version Architecture Description
    +++-==================================-======================-======================-=========================================================================
    ii micropython-ev3dev2 2.1.0 all Python language bindings for ev3dev for MicroPython
    ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev
    ii python3-ev3dev2 2.1.0 all Python language bindings for ev3dev

I have certain programs that crash on EV3Dev2 when 2 parallel Threads may control the same Motor. The crashes have different error messages on MicroPython vs. Python3. I have reproduced the errors in the enclosed test scripts "BUG.SameMotor.Threading.EV3Dev2.MicroPython.py" and "BUG.SameMotor.Threading.EV3Dev2.Python3.py".

For comparison, I have also tried and enclosed below other variations (e.g. using ev3dev(1.2.0) or pybricks instead of ev3dev2, or using multiprocessing or PyBricks's run_parallel instead of threading) that run successfully.

All these programs do the following: turn the Motor clockwise when the Touch Sensor is pressed, or turn the same Motor counter-clockwise when any IR Remote Control button is pressed. The observations from all the coding variations are as follows:

  1. threading with ev3dev2 2.1.0 on micropython: CRASHED after pressing the IR Remote Control buttons a few times (making the Motor turn counter-clockwise), even if the Touch Sensor is NOT pressed at all (i.e. that Touch-Sensor-triggered Thread never commands the Motor at all).

File "ev3dev2/motor.py", line 1048, in on_for_seconds
File "ev3dev2/motor.py", line 928, in wait_until_not_moving
File "ev3dev2/motor.py", line 908, in wait
OSError: 4

  1. threading with ev3dev2 2.1.0 on python3: CRASHED when the Touch Sensor and an IR Remote Control button are pressed at the same time, i.e. both Thread are trying to command the Motor at the same time. But the program runs ok when only 1 button is pressed.

File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 1048, in on_for_seconds
self.wait_until_not_moving()
File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 928, in wait_until_not_moving
return self.wait(lambda state: self.STATE_RUNNING not in state or self.STATE_STALLED in state, timeout)
File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 908, in wait
self._poll.poll(poll_tm)
RuntimeError: concurrent poll() invocation

  1. multiprocessing with ev3dev2 2.1.0 on micropython: both Processes run successfully WITH mutual blocking, i.e. 1 Process CANNOT interrupt/reverse the other Process's Motor movement mid-stream

  2. multiprocessing with ev3dev2 2.1.0 on python3: both Processes run successfully WITH mutual blocking, i.e. 1 Process CANNOT interrupt/reverse the other Process's Motor movement mid-stream

  3. threading with ev3dev (1.2.0) on python3: both Threads run successfully WITHOUT mutual blocking, i.e. 1 Thread CAN interrupt/reverse the other Thread's Motor movement mid-stream

  4. multiprocessing with ev3dev (1.2.0) on python3: both Processes run successfully WITHOUT mutual blocking, i.e. 1 Process CAN interrupt/reverse the other Process's Motor movement mid-stream

  5. threading with pybricks (2.0.0) on pybricks-micropython: both Threads run successfully WITH mutual blocking, i.e. 1 Thread CANNOT interrupt/reverse the other Thread's Motor movement mid-stream

  6. run_parallel (experimental PyBricks feature) with pybricks (2.0.0) on pybricks-micropython: both Threads run successfully WITH mutual blocking, i.e. 1 Thread CANNOT interrupt/reverse the other Thread's Motor movement mid-stream

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