Closed golddranks closed 2 months ago
Asking to make AuthorizedSession thread-safe, so we could just stick it into a singleton object. This seems to be hard, because the underlying Requests isn't apparently thread-safe.
Is wrapping the AuthorizedSession with a mutex an option?
I am not keen on making AuthorizedSession pickle-able but I have not done a thorough investigation.
We chatted about this and we don't believe we will support pickling AuthorizedSession
s. Please re-open this if you have any more questions!
Is your feature request related to a problem? Please describe. In our Django application, to access some Google API's as a part of the processing for some requests, we are currently creating a
AuthorizedSession
per request where it's needed. However, this tends to take some time, from 0.5 seconds to 1.0 second. In some cases, we are getting bursts of 5-10 subsequent requests, and the time of authorizing sessions might delay the user getting the end result by multiple seconds. We'd like to cacheAuthorizedSession
, and it would be enough to cache it in Django'sLocMemCache
, but this requires the cached object to be pickleable, so we are currently unable to do that.Describe the solution you'd like Make
AuthorizedSession
pickleable, so the caches would work. Currently many of the_
attributes get lost. Here is a comparision ofdir()
before and after pickling:vs.
The difference seems to be:
And indeed, the error when trying with cache, is about missing
_auth_request
.Describe alternatives you've considered
AuthorizedSession
thread-safe, so we could just stick it into a singleton object. This seems to be hard, because the underlying Requests isn't apparently thread-safe.AuthorizedSession
as is. This would bring some unrelated complexity from the framework and utility libraries, to the application side, so it doesn't feel quite right to do as the first go-to option.