I thought it was worth drawing attention to this as it's a significant enhancement.
Thanks to @jimmo uasyncio has an official thread safe way to interface with code such as interrupt service routines and code running in another thread. This is documented here. I have also updated my tutorial with some usage examples.
My irq_event primitive is now deleted. It did the same thing, using the same I/O stream technique. Just less elegantly coded
New uasyncio feature: ThreadSafeFlag
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
New uasyncio feature: ThreadSafeFlag
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: New uasyncio feature: ThreadSafeFlag
Thanks Peter! And great to see this in your tutorial already. Sorry this was a long time coming.pythoncoder wrote: ↑Fri Feb 19, 2021 6:00 pmThanks to @jimmo uasyncio has an official thread safe way to interface with code such as interrupt service routines and code running in another thread. This is documented here. I have also updated my tutorial with some usage examples.
The implementation is a bit sub-optimal but we'll need some more architectural changes to improve it, but the API should stay the same. Eventually uevent (or something like it) will allow this to do some neat stuff with low power management.
Worth noting that this is only supported in nightly builds for now, and will be part of the upcoming 1.15 release.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: New uasyncio feature: ThreadSafeFlag
Good point. I've added a note to that effect.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: New uasyncio feature: ThreadSafeFlag
Hi,
What would be the best approach to set ThreadSafeFlag from C code, possibly from another thread or interrupt context?
What would be the best approach to set ThreadSafeFlag from C code, possibly from another thread or interrupt context?
Re: New uasyncio feature: ThreadSafeFlag
This is an area we're still trying to sort out. See https://github.com/micropython/micropython/pull/6125 and the linked PRs.
Basically the idea is that peripheral drivers (in C or Python) should be able to signal (via uevent, or whatever the mechanism is), and then asyncio is "polling" uevent. This means we can centralise all the event sources and simplify power management etc.
In the short term, the way modbluetooth & aioble does it is the C code raises a regular Python callback, and that calls ThreadSafeFlag::set.