Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the global default timeout

Python 3.4 . Trying to find what is the default timeout in urllib.request.urlopen() .

Its signature is: urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None)

The doc says that its "global default timeout", and looking at the code its: socket._GLOBAL_DEFAULT_TIMEOUT

Still what is the actual value in secs?

like image 658
user3139774 Avatar asked Apr 15 '15 11:04

user3139774


People also ask

What is global timeout in UVM?

Global timeout is the maximum limit of simulation execution. This determines the end-of-test timeout. The default value of timeout is set to 9200s. One can also use run time plusarg +UVM_TIMEOUT=, to set the timeout value. Refer to this page for more information on UVM_TIMEOUT from command line processor.

What is the default timeout for urlopen?

If no timeout is supplied, the global default timeout setting returned by :func:getdefaulttimeout is used. So it looks like Py_None, aka None, is the default timeout. In other words, urlopen never times out. At least not from the Python end.

Why do we need _global_default_timeout?

Here is my understanding, the reason for having _GLOBAL_DEFAULT_TIMEOUT is to have a global default timeout value that can be accessible via various application layer modules (like ftplib, httplib, urllib).

Is it possible to have a variable default timeout?

It would really save a lot of time to have a variable default timeout. For most workflows you only need a <5sec timeout and it would save SO MUCH time in the development as well. For most workflows you only need a <5sec timeout and it would save SO MUCH time in the development as well. Are you automating web with WAIT_FOR_READY = Complete?


1 Answers

I suspect this is implementation-dependent. That said, for CPython:

From socket.create_connection,

If no timeout is supplied, the global default timeout setting returned by :func:getdefaulttimeout is used.

From socketmodule.c,

static PyObject * socket_getdefaulttimeout(PyObject *self) {     if (defaulttimeout < 0.0) {         Py_INCREF(Py_None);         return Py_None;     }     else         return PyFloat_FromDouble(defaulttimeout); } 

Earlier in the same file,

static double defaulttimeout = -1.0; /* Default timeout for new sockets */ 

So it looks like Py_None, aka None, is the default timeout. In other words, urlopen never times out. At least not from the Python end. I guess a timeout can still occur if the networking functions supplied by the OS have timeouts themselves.


Edit: oops, I guess I didn't need to go source diving for the answer at all, since it's right there in the docs.

A value of None indicates that new socket objects have no timeout. When the socket module is first imported, the default is None.

like image 198
Kevin Avatar answered Sep 21 '22 08:09

Kevin