Skip to content

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

@jarq6c

Description

@jarq6c

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions