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

Timeout of Dataset constructor #684

Open
knutfrode opened this issue Jun 27, 2017 · 7 comments
Open

Timeout of Dataset constructor #684

knutfrode opened this issue Jun 27, 2017 · 7 comments

Comments

@knutfrode
Copy link

For our operational service it would be useful with possibility to specify a timeout on calling netcdf4.Dataset on remote datasets (Thredds/OPeNDAP), e.g.:

f = Dataset(OPeNDAP_URL, 'r', timeout=10)
@jswhit
Copy link
Collaborator

jswhit commented Jun 28, 2017

This might be possible using the signals module (https://docs.python.org/3/library/signal.html#example).

If anyone wants to tackle this, a pull request would be welcome.

@jswhit
Copy link
Collaborator

jswhit commented Jun 28, 2017

I think this can be done now by setting the TIMEOUT variable in the .daprc file that the C library uses.

https://www.unidata.ucar.edu/software/netcdf/docs/auth.html

@knutfrode
Copy link
Author

You are right, it helps to add e.g. HTTP.TIMEOUT=5 to .dodsrc (probably same with .daprc).

This is an ok solution, although it would still be nice to be able to control it explicitly through Python.

@jerabaul29
Copy link

Same problem here, I had some cases when some scripts got frozen following some gateway problems on a server.

Do you think that it would be possible to make this into a 'native' feature of the Dataset constructor, and / or to timeout / raise an exception by default when this happens?

@jswhit
Copy link
Collaborator

jswhit commented Jul 9, 2020

The C API (which the python interface uses) does not provide an explicit way to set the timeout.

@jerabaul29
Copy link

Ok. That is a bit sad, but guess not much to be done there from Python then. Do you think it may be possible to try something else as a workaround, for example, checking for a valid ping in the case of an url, or something like that? Could that help for the cases when the server may be completely down?

@jswhit
Copy link
Collaborator

jswhit commented Jul 9, 2020

Perhaps a Dataset wrapper or subclass could be created for working with remote OpenDAP datasets, with additional features like this. A PR would be welcome.

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

3 participants