Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peterhinch opened this issue Jul 25, 2018 · 0 comments
Open

Comments

@peterhinch
Copy link
Contributor

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant