← index #295PR #5841
Related · high · value 0.338
QUERY · ISSUE

uasyncio would benefit from a function to check for event loop instance

openby peterhinchopened 2018-07-25updated 2018-07-25

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')
CANDIDATE · PULL REQUEST

extmod/uasyncio: Don't create a Loop instance in get_event_loop().

mergedby dpgeorgeopened 2020-03-30updated 2020-04-01
extmod

The event loop is (for now) just a singleton so make it so that Loop instances are not needed.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied