multi-threading question
multi-threading question
Does the _thread module take advantage of the dual cores of esp32?
If I create 2 threads, will they be scheduled to be running on separate core?
thanks
a-ha
If I create 2 threads, will they be scheduled to be running on separate core?
thanks
a-ha
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: multi-threading question
I'm pretty sure the answer is no: MicroPython runs on one core and FreeRTOS on the other.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: multi-threading question
That's right. At startup a FreeRTOS task is created for MicroPython, pinned to core 1, and all threads are also pinned to this core.
From memory the most recent discussion of this topic was here -- https://github.com/micropython/micropython/issues/4895
From memory the most recent discussion of this topic was here -- https://github.com/micropython/micropython/issues/4895
Re: multi-threading question
Ok I see. FreeRTOS is used by micropython? Nice. Is this only for the esp32 board ? or for all cpu's?
Re: multi-threading question
Does MicroPython still work on one core of ESP32?
Re: multi-threading question
Even under vanilla Python, thread would use only one core ...
Re: multi-threading question
https://www.youtube.com/watch?v=9vvobRfFOwk
according to this video, Raspberry pi pico uses 2 cores with MicroPython. I should buy pico when it is available in my country.
according to this video, Raspberry pi pico uses 2 cores with MicroPython. I should buy pico when it is available in my country.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: multi-threading question
still applies. Given that the ESP32 runs FreeRTOS this is probably the most efficient way to use its two cores.
In general threading and Python don't coexist too well because of the GIL: this limits the benefit of running on multiple cores. If there is a single Python runtime, threads can cause each other to stall. I think there are nonstandard Python implementations which aim to resolve this, but I have no real knowledge of them.
A MicroPython exception is the Raspberry Pi Pico where two independent MicroPython runtimes can coexist, one on each core. This is magic, and the way to go
In MicroPython cooperative multitasking running on one core is more efficient than threading on one core.
In general threading and Python don't coexist too well because of the GIL: this limits the benefit of running on multiple cores. If there is a single Python runtime, threads can cause each other to stall. I think there are nonstandard Python implementations which aim to resolve this, but I have no real knowledge of them.
A MicroPython exception is the Raspberry Pi Pico where two independent MicroPython runtimes can coexist, one on each core. This is magic, and the way to go
In MicroPython cooperative multitasking running on one core is more efficient than threading on one core.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: multi-threading question
I don’t have any experience with threading in micropython, but according to the docs, _thread in micropython works just like in vanilla Python. There, threading uses the same core. To use multiple cores, we need to use multiPROCESSING. Most likely, the Swiss guy was tricked into believing threading uses multiple cores