Page 1 of 1

thread vs uasyncio

Posted: Wed Jan 26, 2022 3:41 pm
by Pauline_Carlson
Hello there,

My project needs multithreading and some kind of locks.
As far as I know, _thread has not supported any kind of locks.
So do you know a workaround for that?
async could be one, but it is not supported on pycom boards. Is there a way to use it?
Which path should I choose?

Re: thread vs uasyncio

Posted: Wed Jan 26, 2022 6:51 pm
by pythoncoder
The _thread module is experimental and poorly documented. However you should be able to issue

Code: Select all

lock = _thread.allocate_lock()
lock.acquire()
# ...
lock.release()
That said, uasyncio is the best solution in most cases: it is very much more efficient on lightweight targets. Developing under cooperative schedulers is much easier than with preemptive ones. I can point you at docs to support this assertion if you wish.

If Pycom don't support asynchronous programming, their firmware is ill suited for serious applications (in my opinion).