You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using httplib2 in python function through Google API python client.
Recently was added to Google API python client a close()method relying on http.close().
My google Drive connector is a class:
Google Drive service is created in init and becomes a property of my Google drive object. So I will certainly not use the close()method that was implemented in this lib as I need to re-use this serviceproperty afterwards.
to manage 'thread-safety', I create an http object for each connection in a dedicated function (as recommended in Google Drive documentation).
For instance to upload a file:
importhttplib2defwrite(self, folder_id: str, file_name: str, **kwargs):
# Upload (caching the authorized `http` object used to run `next_chunk()`)media=googleapiclient.http.MediaFileUpload(file_name, resumable=True)
file_metadata= {'name': file_name, 'parents': [folder_id]}
request=self.drive.files().create(body=file_metadata, media_body=media, fields='id')
# Set timeout to 10 minutes for upload of big chunks (is used when creating the `http` object)socket.setdefaulttimeout(600)
auth_http=googleapiclient._auth.authorized_http(self.creds) # here, creation of my local http objectauth_http.cache=httplib2.FileCache(self.cache_path)
response=NonewhileresponseisNone:
status, response=request.next_chunk(num_retries=4, http=auth_http)
# shoud I add here a call to close this http object?
Ok, this all seems very Google API python client related, sorry for the long introduction. :)
Now the httplib2 related question.
After the 10mn timeout I have setup in this write()function, will the httpobject naturally close, or do I have to call the http.close()method to ensure it is closed?
I thank you for your guidance.
Have a good day,
Bests,
The text was updated successfully, but these errors were encountered:
yohplala
changed the title
When using httep.close()?
When using http.close()?
Sep 24, 2020
In general you can call Http.close() when you know you will not be doing more requests to same hosts for a while. It only applies to long lived Http objects. If your auth_http goes out of scope and deleted by reference counter, it should close all connections without explicit .close() call.
Please open separate bug report if you observe background connections not closed after destructing Http object. That would be a bug.
Hi,
I am using httplib2 in python function through Google API python client.
Recently was added to Google API python client a
close()
method relying onhttp.close()
.My google Drive connector is a class:
init
and becomes a property of my Google drive object. So I will certainly not use theclose()
method that was implemented in this lib as I need to re-use thisservice
property afterwards.For instance to upload a file:
Ok, this all seems very Google API python client related, sorry for the long introduction. :)
Now the
httplib2
related question.After the 10mn timeout I have setup in this
write()
function, will thehttp
object naturally close, or do I have to call thehttp.close()
method to ensure it is closed?I thank you for your guidance.
Have a good day,
Bests,
The text was updated successfully, but these errors were encountered: