micropython / micropython/micropython-lib
uasyncio would benefit from a function to check for event loop instance
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
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')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in uasyncio.core.py by reading the _event_loop state and get_event_loop implementation. Add the proposed event-loop presence check, then verify that it distinguishes an uninitialized loop from an existing one and supports the usage shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100