NOAA-OWP / hydrotools

Suite of tools for retrieving USGS NWIS observations and evaluating National Water Model (NWM) data.
Other
54 stars 13 forks source link

Jupyter Notebook RuntimeError: This event loop is already running #139

Closed jarq6c closed 2 years ago

jarq6c commented 3 years ago

Duplicate

from hydrotools.nwis_client.iv import IVDataService

data_service = IVDataService(value_time_label="value_time")
stage_df = data_service.get(
    sites=["01646500", "01013500"],
    startDT="2019-08-01",
    endDT="2019-09-01",
    parameterCd="00065"
)

Tagging @aaraney for advice. It seems #100 fixed the issue in Google Collab, but it still persists in Jupyter Notebook and Spyder (which may have further issues with asyncio).

Running the code above inside a Jupyter Notebook or from Spyder resulted in RuntimeError: This event loop is already running.

Fix

You can resolve the error by adding

import nest_asyncio
nest_asyncio.apply()
aaraney commented 3 years ago

@jarq6c thanks for tagging me here. It looks like hydrotools._restclient version 3.0.4 from #130 was never published to pypi. I can take care of that and it should resolve the issue. We likely want to pin the _restclient version nwis_client is using to >=3.0.4.

jarq6c commented 3 years ago

That would be my oversight! Go ahead and publish an updated _restclient to PyPI if you can.

aaraney commented 3 years ago

The new _restclient version is now up.

aaraney commented 3 years ago

I just verified that 3.0.4 resolves the issue in jupyter lab. I will open a PR to require 3.0.4 or higher in nwis_client!