Multiprocessing / multithreading

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
liorabel
Posts: 1
Joined: Tue Aug 26, 2014 2:08 pm

Multiprocessing / multithreading

Post by liorabel » Tue Aug 26, 2014 2:21 pm

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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Multiprocessing / multithreading

Post by dhylands » Wed Aug 27, 2014 1:58 am

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

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Multiprocessing / multithreading

Post by kfricke » Wed Aug 27, 2014 12:08 pm

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.

fma
Posts: 164
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: Multiprocessing / multithreading

Post by fma » Wed Aug 27, 2014 12:20 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiprocessing / multithreading

Post by pythoncoder » Thu Aug 28, 2014 6:46 am

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
Peter Hinch
Index to my micropython libraries.

moefear85
Posts: 5
Joined: Sat Oct 30, 2021 12:44 pm

Re: Multiprocessing / multithreading

Post by moefear85 » Sat Oct 30, 2021 12:45 pm

micropython-lib supports multiprocessing (see unix-ffi)

User avatar
curt
Posts: 25
Joined: Thu Jul 29, 2021 3:52 am
Location: Big Lake, Alaska

Re: Multiprocessing / multithreading

Post by curt » Mon Nov 01, 2021 4:11 pm

Multiprocessing could easily overwhelm a Pyboard (or similar). Could change your design to utilize multiple Pyboards all communicating with a central host?

Curt

ifishtoo
Posts: 1
Joined: Wed Nov 24, 2021 4:31 am

Re: Multiprocessing / multithreading

Post by ifishtoo » Wed Nov 24, 2021 4:35 am

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.

User avatar
Wind-stormger
Posts: 17
Joined: Fri Nov 05, 2021 6:59 am

Re: Multiprocessing / multithreading

Post by Wind-stormger » Thu Dec 02, 2021 1:04 am

At this time, it is wise to use timer to make task arrangement more accurate and compact~

Post Reply