Multi-threading support, sponsored by Pycom

Announcements and news related to MicroPython.
mkarliner
Posts: 8
Joined: Fri Sep 09, 2016 10:59 am

Re: Multi-threading support, sponsored by Pycom

Post by mkarliner » Fri Sep 09, 2016 4:47 pm

I can't see the 'threading' branch in the main repo, and I it doesn't seem to be
merged into master. Where can I find it now?

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

Re: Multi-threading support, sponsored by Pycom

Post by pythoncoder » Sat Sep 10, 2016 5:33 am

The lower level _thread library is supported on the WiPy, but as far as I can see hasn't yet made it to the Pyboard.
Peter Hinch

gratefulfrog
Posts: 144
Joined: Sun Mar 01, 2015 12:10 pm

Re: Multi-threading support, sponsored by Pycom

Post by gratefulfrog » Fri Dec 30, 2016 2:55 pm

Hi guys!

Any news on this? I'm waiting for it to come to the pyboard, as I just spent weeks debugging problems which would not have occurred if I had working threads...

Ciao,
Bob

nic
Posts: 1
Joined: Tue Dec 18, 2018 12:08 pm

Re: Multi-threading support, sponsored by Pycom

Post by nic » Tue Dec 18, 2018 12:19 pm

Hi,

I am trying to create a Bridge between UART and Bluetooth with the wipy.
So, another device, call it Device_A, can connect via UART to the wipy and send Data to a Bluetooth HUB and later also to a Server via Wifi.
When Data is send succesfully to the Server, or HUB, a notification should be sent back to Device_A through the bridge(wipy).
I have a first idea of how to do this. I need 4 threads:
1. Read Uart ( Wait for Chars, read in frame, SENT TO BUFFER1/ QUEUE1/..)
2. Process Frame (Wait for Frame in Buffer1/ Queue1..., Process Frame: Send Data via Wifi/BLE.., Write to Buffer2)
3. Bluetooth (Wait for Events, process events.., write to Buffer2)
4. Write UART (Wait for Frames in Buffer2, Write to UART)

The module "uasyncio" would be perfect to use here, but unfortunately I have a Wipy-board.

What would be an alternative here? _threads? This has very limited functionalities..

User avatar
Roberthh
Posts: 1164
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Multi-threading support, sponsored by Pycom

Post by Roberthh » Tue Dec 18, 2018 2:02 pm

Since you mention Bluetooth and WiPy, I assum that you use a WiPy2 or WiPy3 from Pycom with an ESP32 processor.
For that device you have to ask as forum.pycom.io.
Besides that, you may use uasyncio in both variants of MicroPython with slight differences.

User avatar
mattyt
Posts: 159
Joined: Mon Jan 23, 2017 6:39 am

Re: Multi-threading support, sponsored by Pycom

Post by mattyt » Wed Dec 19, 2018 3:11 am

For the record, Damien presented Threads in MicroPython at our recent MicroPython Meetup. It can be difficult to see Damien's screen but hopefully you can get the gist.

The summary is that he's recently tidied up the _thread implementation on the ESP32 and so threading is now viable on the ESP32 and the PyBoard. The interface is identical between the ports. In particular there were some bugs wrt running multiple threads with PSRAM-enabled ESP32's.

The on-the-spot examples he came up with were pretty compelling! Pretty neat to run a thread in the background while using the REPL. If I need concurrency I'd first reach for an asyncio solution but it's good to have options. :)

As @nic mentioned, only the _thread module is currently available. The threading module, which adds many more higher-level abstractions, is a pure-python library built on top of the primitives supplied by _thread. For someone sufficiently motivated, it shouldn't be a massive task to start porting CPython's threading source code to MicroPython...

PS I've only just posted that video and haven't yet processed the other videos from the night but when I get around to it I'll add the usual entry to the Melbourne MicroPython Meetup blog.

Post Reply