Page 2 of 2

Re: Multi-threading support, sponsored by Pycom

Posted: Fri Sep 09, 2016 4:47 pm
by mkarliner
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?

Re: Multi-threading support, sponsored by Pycom

Posted: Sat Sep 10, 2016 5:33 am
by pythoncoder
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.

Re: Multi-threading support, sponsored by Pycom

Posted: Fri Dec 30, 2016 2:55 pm
by gratefulfrog
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...


Re: Multi-threading support, sponsored by Pycom

Posted: Tue Dec 18, 2018 12:19 pm
by nic

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..

Re: Multi-threading support, sponsored by Pycom

Posted: Tue Dec 18, 2018 2:02 pm
by Roberthh
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
Besides that, you may use uasyncio in both variants of MicroPython with slight differences.

Re: Multi-threading support, sponsored by Pycom

Posted: Wed Dec 19, 2018 3:11 am
by mattyt
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.