Multiprocessing / multithreading
Multiprocessing / multithreading
I tried searching for materials and through this forum but couldn't find any information on this.
Does MicroPython (and of course the Pyboard) support multiprocessing or multithreading? I'd prefer the former for simplicity and performance reasons.
An example of why this would be useful is a robot where every sensor or motor has its own controlling process and there is 1 main process orchestrating those and sending out control instructions.
Does MicroPython (and of course the Pyboard) support multiprocessing or multithreading? I'd prefer the former for simplicity and performance reasons.
An example of why this would be useful is a robot where every sensor or motor has its own controlling process and there is 1 main process orchestrating those and sending out control instructions.
Re: Multiprocessing / multithreading
Micropython doesn't support multiprocessing or multithreading in the sense of preemptive multithreading.
Everything in Micropython runs in a single thread.
However, you can get the effect of threading as was discussed here:
http://forum.micropython.org/viewtopic.php?f=2&t=15
and in particular, this post: http://forum.micropython.org/viewtopic. ... hread#p208 has some sample code.
pythoncoder put together a scheduler here: forum.micropython.org/viewtopic.php?f=2&t=269&p=1341&hilit=scheduler#p1341
Everything in Micropython runs in a single thread.
However, you can get the effect of threading as was discussed here:
http://forum.micropython.org/viewtopic.php?f=2&t=15
and in particular, this post: http://forum.micropython.org/viewtopic. ... hread#p208 has some sample code.
pythoncoder put together a scheduler here: forum.micropython.org/viewtopic.php?f=2&t=269&p=1341&hilit=scheduler#p1341
Re: Multiprocessing / multithreading
imho and especially in robot operation, deterministic real-time behavior is more important than multi"anyth"ing. You should try to pick up what evolution has learned for us... Complex organisms need a spinal column that can react in real-time to sensory feedback while relaying the sensor data to be forwarded to the "brain", which of course should be able to send commands to the actuators by implementing some sort of "multitasking".
I do not want to suggest that you would not need multi"anyth"ing in your pyboard, but the sensor "control" you mentioned should be implemented different. A good way would be to use something "more stupid" to implement real-time-critical sensory stuff. e.g. an minimal Arduino would be a good choice.
I do not want to suggest that you would not need multi"anyth"ing in your pyboard, but the sensor "control" you mentioned should be implemented different. A good way would be to use something "more stupid" to implement real-time-critical sensory stuff. e.g. an minimal Arduino would be a good choice.
Re: Multiprocessing / multithreading
You may don't need to exactly react in real time, but at least exactly know *when* you reacted. And I think micropython can do this, using precise timer for time measurement.
Frédéric
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Multiprocessing / multithreading
Cooperative multitasking is just a programming technique. You sacrifice deterministic response and a degree of overall performance. But in some cases you gain in code clarity, maintainability and size, sometimes substantially. Each application should be judged on its merits.
Regards, Pete
Regards, Pete
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Multiprocessing / multithreading
micropython-lib supports multiprocessing (see unix-ffi)
Re: Multiprocessing / multithreading
Multiprocessing could easily overwhelm a Pyboard (or similar). Could change your design to utilize multiple Pyboards all communicating with a central host?
Curt
Curt
Re: Multiprocessing / multithreading
I found this post...
https://pypi.org/project/micropython-multiprocessing/
There is a multi-processing module for python. This particular module appears to be a cut down version that is not fully implemented just yet.
https://pypi.org/project/micropython-multiprocessing/
There is a multi-processing module for python. This particular module appears to be a cut down version that is not fully implemented just yet.
- Wind-stormger
- Posts: 17
- Joined: Fri Nov 05, 2021 6:59 am
Re: Multiprocessing / multithreading
At this time, it is wise to use timer to make task arrangement more accurate and compact~