msm1089 / ipynbname

Simple utility that retrieves current Jupyter notebook filename or path, when run from Jupyter notebook.
MIT License
57 stars 8 forks source link

Option to reduce the request timeout #23

Open thangleiter opened 10 months ago

thangleiter commented 10 months ago

_list_maybe_running_servers() finds 20 possible servers on my system when no notebook is running. This means that name() will run for around 20 seconds because every urllib.request.urlopen() call will only timeout after 1s.

I played around with sending a HEAD request first to test if the url is being served, but it seems like that's not an allowed method in this case.

So my suggestion would be to add an optional timeout argument to name() and path() which lets the user decide how long to wait for the timeout. Something on the order of 5 ms still worked reliably for me, but in the currently used 500 ms could be set as the default.