requests.{get,post} timeout
Chris Angelico
rosuav at gmail.com
Thu Aug 24 20:54:28 EDT 2017
On Fri, Aug 25, 2017 at 10:42 AM, Jon Ribbens <jon+usenet at unequivocal.eu> wrote:
> On 2017-08-24, Chris Angelico <rosuav at gmail.com> wrote:
>> Only in the sense that "kill" is the Unix term for "send signal".
>> Python catches the signal, the system call terminates with EINTR, and
>> the exception is raised. Give it a try.
>
> Give what a try? Pressing ctrl-c? That'll kill the process.
> Obviously we all agree that killing the entire process will
> terminate the request and all resources associated with it.
>>> import requests
>>> requests.get("http://192.168.0.1/")
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line
56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py",
line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py",
line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py",
line 423, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py",
line 600, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py",
line 356, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/http/client.py", line 1230, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1225, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1017, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 955, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/requests/packages/urllib3/connection.py",
line 166, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.7/site-packages/requests/packages/urllib3/connection.py",
line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.7/site-packages/requests/packages/urllib3/util/connection.py",
line 73, in create_connection
sock.connect(sa)
KeyboardInterrupt
>>>
That looks like an exception to me. Not a "process is now terminated".
That's what happened when I pressed Ctrl-C (the IP address was
deliberately picked as one that doesn't currently exist on my network,
so it took time).
ChrisA
More information about the Python-list
mailing list