Is there a built-in support for waiting a thread to complete in MicroPython (eg. on ESP32 or RPi Pico)?
If not, then can you recommend a technique for achieving this? Something less ugly than sleeping in a loop and checking a shared flag?
My goal is to recommend a work-around for Thonny users, who get errors when they are using threads (eg. https://github.com/thonny/thonny/issues/1586). When Thonny detects REPL prompt, it thinks the device is idle and it can issue hidden commands (eg. for listing files) without being disturbed. Printing from a thread invalidates this expectation.
I know Thonny should try harder and distinguish the output meant for user from the output from management commands, but for a work-around it would be good if it was possible to organize the user code such that the main thread doesn't return to the prompt before all background threads are done.
How to join threads?
- aivarannamaa
- Posts: 171
- Joined: Fri Sep 22, 2017 3:19 pm
- Location: Estonia
- Contact:
How to join threads?
Aivar Annamaa
https://thonny.org
https://thonny.org
Re: How to join threads?
Unfortunately not that I'm aware of.aivarannamaa wrote: ↑Mon Feb 01, 2021 2:38 pmIs there a built-in support for waiting a thread to complete in MicroPython (eg. on ESP32 or RPi Pico)?
That's pretty much how join works under the hood but yeah probably a neater solution than using a flag directly is to use a mutex held by the thread and the main thread shouldn't exit until it can acquire the mutex.aivarannamaa wrote: ↑Mon Feb 01, 2021 2:38 pmIf not, then can you recommend a technique for achieving this? Something less ugly than sleeping in a loop and checking a shared flag?
Re: How to join threads?
There is some discussion on The Ras Pi Pico Forum but it was a bit above my current experience:
https://www.raspberrypi.org/forums/view ... &p=1808139
https://www.raspberrypi.org/forums/view ... &p=1808139