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

"RuntimeError: There is no current event loop in thread 'Dummy-1'" - asyncio issue with potential fix #373

Open
sc0ned opened this issue Nov 25, 2021 · 1 comment

Comments

@sc0ned
Copy link

sc0ned commented Nov 25, 2021

Hey guys, after updating I kept getting the error in the title so I did a little digging and found a potential fix here - https://techoverflow.net/2020/10/01/how-to-fix-python-asyncio-runtimeerror-there-is-no-current-event-loop-in-thread/. The issue was with the following line in v2.py:
return asyncio.get_event_loop().run_until_complete(_get())

and my fix was replacing "asyncio.get_event_loop()" with a call to the following function:

def get_or_create_eventloop():
    try:
        return asyncio.get_event_loop()
    except RuntimeError as ex:
        if "There is no current event loop in thread" in str(ex):
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            return asyncio.get_event_loop()

Making the new line: return get_or_create_eventloop().run_until_complete(_get())
Not sure if this will apply to everyone but figured I'd share in case someone else runs into the issue

@mostdoqe
Copy link

Hello could you give me your discord or telegram

jevonyeoh added a commit to featurebyte/featurebyte that referenced this issue Mar 3, 2023
There's a bunch of errors of the form 
  RuntimeError: There is no current event loop in thread 'Dummy-1'. 
that pop up once in a while on failing integration tests.

Example: https://github.com/featurebyte/featurebyte/actions/runs/4320831275/jobs/7541472752

Some googling suggests we can try to avoid this by having some extra handling around the event loop fixture.

Related links
- https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler
- ultrafunkamsterdam/undetected-chromedriver#373
- pytest-dev/pytest-asyncio#257

I don't think this necessarily solves the underlying issue, but figured it might be worth 
a try to try to make a short-term patch to alleviate some flaky integration tests.
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

2 participants