uasyncio would benefit from a function to check for event loop instance
I appreciate that this is unlikely to be a priority but I thought it worth recording for future reference. There is scope for a subtle bug to occur in user code where a contributed module is used:
import uasyncio as asyncio
import some_module
bar = some_module.Bar() # Constructor calls get_event_loop()
# and renders these args inoperative
loop = asyncio.get_event_loop(runq_len=40, waitq_len=40)
I can envisage this puzzling users unfamiliar with the code of uasyncio and/or some_module. It could be avoided (with a trivial got_event_loop() function) if the class could test for instantiation.
uasyncio.core.py:
def got_event_loop():
return _event_loop is not None
In some_module:
class Foo():
def __init__(self):
if asyncio.got_event_loop():
loop = asyncio.get_event_loop()
loop.create_task(self._run())
else:
raise OSError('Foo class requires an event loop instance')
uasyncio: feature request: multiple event loops
I think this needs to go here and not in the micropython-libs repo...
A project I'm working on has two main contexts code can run in. Previously I had modeled those two contexts as two different event loops, with an explicit hand-off between them.
One loop was the "motion control" event loop. It was a higher priority and there were only specific spots it would be able to stop at safely. I could turn it into a blocking function (with the help of interrupts to handle some edge cases) but there are reasons why it's better for it to be co-operative multi-tasking based. The idea was that it would call motionLoop.stop() at regular intervals to allow the general loop to run.
The other loop was the general purpose loop which would run things like user plugins, a web interface, GC, etc.
Any thoughts?