micropython / micropython/micropython-lib
uasyncio would benefit from a function to check for event loop instance
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 2.9k
- Forks
- 1.1k
- Ø Merge
- 7 T. 6 Std.
- Gemergte PRs (30 T.)
- 3
Beschreibung
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')
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in uasyncio.core.py mit dem Lesen des Zustands von _event_loop und der Implementierung von get_event_loop. Füge die vorgeschlagene Prüfung auf das Vorhandensein der Ereignisschleife hinzu und überprüfe anschließend, dass sie eine nicht initialisierte Schleife von einer vorhandenen unterscheidet und die im Issue gezeigte Verwendung unterstützt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 38/100