-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
Comments
|
|
|
|
|
|
|
|
Yeah, multi-threaded access to the same motor is not (officially) supported, unfortunately. It's curious that your results seem to indicate that stock motors work un-modified with the v1.0 series; I am not sure why there's a difference there, probably due to blocking logic changes. It might be worth diffing the motor code to compare, but then again, since we haven't intentionally designed it to work with concurrent access I don't expect that to be consistent. My suggestion is to go with the mutex version to be safe. |
@WasabiFan the most curious result among the above is from Program no. 1 "BUG.SameMotor.Threading.EV3Dev2.MicroPython.py": the program crashes even when the Touch Sensor is never touched and hence its related Is there a MicroPython compiler that compiles this program and identifies that there is a chance that the Touch-Sensor-related |
That case sounds like this other one: #727 OSError 4 is EINTR, i.e. "system call interrupted". It means that a signal was raised while in a system call, and the system call was aborted to prevent deadlock. This happens because even just the presence of threads means the interpreter (Micropython specifically) will begin triggering signals to synchronize garbage collection. Technical overview aside, it means that multithreading does not play nice with our MicroPython library, unfortunately. I had tried to work toward a true solution of this (starting with #732, to benchmark the speed of our library before adding error handling) but haven't circled back to finish it, implement the error handling, and re-benchmark. There are some notes at the bottom of the thread linked above which might help you work around it. |
We are also getting OSError: 4 errors in wait a significant number of times in micropython. If we shut off odometry_start() from MoveDifferential , would it remove the problem? |
Ah, yeah, odometry uses a thread in the background and may provoke EINTR. |
Thanks |
ev3dev version: 4.14.117-ev3dev-2.3.5-ev3
||/ 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
Thread
s 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) orpybricks
instead ofev3dev2
, or usingmultiprocessing
or PyBricks'srun_parallel
instead ofthreading
) 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:
threading
withev3dev2
2.1.0 onmicropython
: 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-triggeredThread
never commands the Motor at all).threading
withev3dev2
2.1.0 onpython3
: CRASHED when the Touch Sensor and an IR Remote Control button are pressed at the same time, i.e. bothThread
are trying to command the Motor at the same time. But the program runs ok when only 1 button is pressed.multiprocessing
withev3dev2
2.1.0 onmicropython
: bothProcess
es run successfully WITH mutual blocking, i.e. 1Process
CANNOT interrupt/reverse the otherProcess
's Motor movement mid-streammultiprocessing
withev3dev2
2.1.0 onpython3
: bothProcess
es run successfully WITH mutual blocking, i.e. 1Process
CANNOT interrupt/reverse the otherProcess
's Motor movement mid-streamthreading
withev3dev
(1.2.0) onpython3
: bothThread
s run successfully WITHOUT mutual blocking, i.e. 1Thread
CAN interrupt/reverse the otherThread
's Motor movement mid-streammultiprocessing
withev3dev
(1.2.0) onpython3
: bothProcess
es run successfully WITHOUT mutual blocking, i.e. 1Process
CAN interrupt/reverse the otherProcess
's Motor movement mid-streamthreading
withpybricks
(2.0.0) onpybricks-micropython
: bothThread
s run successfully WITH mutual blocking, i.e. 1Thread
CANNOT interrupt/reverse the otherThread
's Motor movement mid-streamrun_parallel
(experimental PyBricks feature) withpybricks
(2.0.0) onpybricks-micropython
: bothThread
s run successfully WITH mutual blocking, i.e. 1Thread
CANNOT interrupt/reverse the otherThread
's Motor movement mid-streamThe text was updated successfully, but these errors were encountered: