Hi,
I have a PyBoard 1.1 and I plan to use this with a multithreading program
The program has been developed on a Rpi and is working well on rpi.
My PyBoard: MicroPython v1.13 on 2020-09-02; PYBv1.1 with STM32F405RG
I see there are one firmware download marked "threading: v1.13-274-g49dd9ba1a (latest)".
Should I update my PyBoard?
Thanks,
Lars
Threading on PyBoard 1.1
Re: Threading on PyBoard 1.1
The threading build is identical to the normal build other than it enables the _thread module and adds some extra locking in a few places.lrb@lrb.no wrote: ↑Tue Jan 19, 2021 12:03 pmI see there are one firmware download marked "threading: v1.13-274-g49dd9ba1a (latest)".
Should I update my PyBoard?
On MicroPython (and regular Python TBH) I'd strongly recommend using asyncio instead of threads though.
-
- Posts: 5
- Joined: Tue Jan 05, 2021 8:39 am
Re: Threading on PyBoard 1.1
Thank you Jimmo!
I'll look into that.
The reasons for using multiprocessing in my original program for RPI was the possibility to use Queues.
If using uasyncio, can you give a hint how to implement something similar?
/Lars
I'll look into that.
The reasons for using multiprocessing in my original program for RPI was the possibility to use Queues.
If using uasyncio, can you give a hint how to implement something similar?
/Lars
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Threading on PyBoard 1.1
CPython's asyncio has a Queue class. There is not yet an official implementation, but an unofficial one may be found here.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 5
- Joined: Tue Jan 05, 2021 8:39 am
Re: Threading on PyBoard 1.1
Thank you pythoncoder!
I've done a simple test of the Queue implementation and it seems to be working very well!
A question, might be a little off topic:
Currently I have four uart with external electronics for RS232, and I need to read and write to all.
In my python program for rpi I used two classes: One for read and one for write, each having their own queue.
Would you recommend using classes on Pyboard 1.1 as well? Or should I use functions? I.E. 8 functions..
Kind regards,
Lars
I've done a simple test of the Queue implementation and it seems to be working very well!
A question, might be a little off topic:
Currently I have four uart with external electronics for RS232, and I need to read and write to all.
In my python program for rpi I used two classes: One for read and one for write, each having their own queue.
Would you recommend using classes on Pyboard 1.1 as well? Or should I use functions? I.E. 8 functions..
Kind regards,
Lars
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Threading on PyBoard 1.1
If you're using uasyncio - which is usually the best approach - you should use the stream mechanism which handles concurrency and buffering.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 5
- Joined: Tue Jan 05, 2021 8:39 am
Re: Threading on PyBoard 1.1
Thank you Peter,
So 8 functions with stream mechanism is your recommendation.
I'll give it a try
/Lars
So 8 functions with stream mechanism is your recommendation.
I'll give it a try
/Lars
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Threading on PyBoard 1.1
You will need eight asynchronous routines. Whether these are functions or bound methods depends on the way you plan to share data. This is down to general programming practice - bound variables or bound objects are generally better practice than using globals.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.