RWTH-EBC/FiLiP

Timeout for get request

Closed this issue · 4 comments

Describe the bug
I am trying to make GET requests continuously. Filip starts every time a new HTTP connection before sending the request. The problem is that it sometimes gets stacked after creating a new connection (see the screenshot). The problem is very similar to this issue in urllib3

Expected behavior
I will expect an error, like a time-out error.

Screenshots
grafik

I suppose we can add a default timeout here

if self.session:
return self.session.get(url=url, params=params, **kwargs)
return requests.get(url=url, params=params, **kwargs)

@djs0109 usually, urllib3 is handling this issue quite. Please also look into the server settings.
If the server closes the connection your client needs to open the connection every time.

Do you reuse your clients? Please try again by using sessions that should maybe help as well.

https://github.com/RWTH-EBC/FiLiP/blob/master/examples/basics/e01_http_clients.py

Please, also check on this one:

https://stackoverflow.com/questions/25239650/python-requests-speed-up-using-keep-alive

I use now Session in ContextBrokerClient. It will not create a new HTTP connection every time. Therefore, the program seems not to be blocked anymore. Maybe the use of Session should be the standard for the use case like mine (i.e. repetitive and continuous requests).

I post my old and new code block here, and close this issue
old:

# Create orion context broker 
self.ORION_CB = ContextBrokerClient(url=self.cb_url, fiware_header=fiware_header)

new:

# Create orion context broker 
s = requests.Session()
self.ORION_CB = ContextBrokerClient(url=self.cb_url, fiware_header=fiware_header, session=s)