A threading.Event() like concept in MicroPython?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

A threading.Event() like concept in MicroPython?

Post by Jibun no kage » Tue Jul 26, 2022 1:15 am

A Python threading.Event() like concept in MicroPython? I happen to be using a Raspberry Pi Pico, so thinking maybe custom class that is interrupt based? Not sure, but figure someone has implemented something similar?

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

Re: A threading.Event() like concept in MicroPython?

Post by pythoncoder » Tue Jul 26, 2022 9:07 am

I suggest you explain more fully what you're trying to achieve. The Pi Pico has two cores and it's possible to use both via the _thread library. Otherwise concurrency is handled by uasyncio see also this doc.
Peter Hinch
Index to my micropython libraries.

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: A threading.Event() like concept in MicroPython?

Post by Jibun no kage » Sat Jul 30, 2022 4:26 pm

Actually I asked this when I first tried to port some straight python to Micro. I soon realized, it would be easier, faster, to just rewrite the solution (a MQTT based project) from a Micro mindset from the ground up. This lead me to asyncio, and then to using mqtt_as, because I was having some issues using mqtt simple then robust in turn. Even considered creating a simple EventClass, but that proved unnecessarily. For one-off timeout need, the native machine.Timer works, or as you would comment, using Polling (i.e. nod to NTP query for example). Of course for periodic timers asyncio create task works, and since I am already using mqtt_as, easy to do.

Post Reply