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

Asynchronous _loop_ref should using the existing event loop if one exists #5102

Open
zags4life opened this issue Apr 4, 2024 · 3 comments · May be fixed by #5103
Open

Asynchronous _loop_ref should using the existing event loop if one exists #5102

zags4life opened this issue Apr 4, 2024 · 3 comments · May be fixed by #5103

Comments

@zags4life
Copy link

Asynchronous.event_loop should get the existing event loop, if one exists. I one does not exist, it should create a new event loop then set the event loop by calling asyncio.set_event_loop so downstream consumers can get access to the same event loop when they call asyncio.get_event_loop.

@property
def event_loop(self):
    if self._loop_ref is None:
        self._loop_ref = asyncio.new_event_loop()  <!-- never sets event loop
    return self._loop_ref
@pekkaklarck
Copy link
Member

Does this look good for you @ygorpontelo? The PR would need some tests before it can be merged.

@ygorpontelo
Copy link
Contributor

The event loop in robot will only be created if no running event loop is found in the first place. In the implementation of #5103 the event loop property will be basically reimplementing functionallity from is_loop_required.

Important to note as well that get_event_loop has a lot of complicated behaviour and can create event loops if none are found, which is also getting deprecated for 3.12 forward. For this, using get_running_loop() is preferred over get_event_loop().

If we have other event loops created in libraries for example, robot should not interfere with them, this ensure's that the resource is properly handled by the library. That said it is simpler for libraries to just implement functions as async and let robot do the rest, better for compatibility as well. Using get_running_loop() should return the correct loop for all purposes.

So i don't see how this change could be useful.

@ygorpontelo
Copy link
Contributor

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

Successfully merging a pull request may close this issue.

3 participants