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

nwis_client: "RuntimeError: There is no current event loop in thread 'MainThread'." #276

Open
jarq6c opened this issue Jan 23, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jarq6c
Copy link
Collaborator

jarq6c commented Jan 23, 2025

When running this code the first time, I get an error.

from hydrotools.nwis_client.iv import IVDataService

obs_client = IVDataService()
gages = obs_client.get(huc="03")

print(gages.head())
Traceback (most recent call last):
  File "main.py", line 44, in <module>
    main()
  File "main.py", line 7, in main
    obs_client = IVDataService()
                 ^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/hydrotools/nwis_client/iv.py", line 112, in __init__
    self._restclient = RestClient(
                       ^^^^^^^^^^^
  File "/lib/python3.12/site-packages/hydrotools/_restclient/_restclient.py", line 91, in __init__
    self._loop = loop or asyncio.get_event_loop()
                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.12/asyncio/events.py", line 702, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.

Running the code a second time results in normal output.

@jarq6c jarq6c added the bug Something isn't working label Jan 23, 2025
@aaraney
Copy link
Member

aaraney commented Jan 24, 2025

Thanks for reporting this, @jarq6c! This might be due to a change in the behavior of asyncio.get_event_loop introduced in python 3.12. I'll take a closer look this afternoon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants