Replies: 3 comments
-
Today I found some time to look through the source and found def __getstate__(self) -> typing.Dict[str, typing.Any]:
return {
name: value
for name, value in self.__dict__.items()
if name not in ["extensions", "stream"]
}
def __setstate__(self, state: typing.Dict[str, typing.Any]) -> None:
for name, value in state.items():
setattr(self, name, value)
self.extensions = {}
self.stream = UnattachedStream() That explains my above problem. But I don't know, why one should remove this data from the object. Some explanation or warning would be nice... |
Beta Was this translation helpful? Give feedback.
-
@cloasdata Hi, just a heads up that you might want to review #1579 for background. It's still possible there are some developer experience niceties we could be adding... |
Beta Was this translation helpful? Give feedback.
-
To be honest I did not understand the background, why Request needs to be pickled exactly this way. But a typical thing one may want to do is to put a fresh request on a queue and when it is time a worker may get this request and send it through the workers client. for now I wrote an simple adapter. |
Beta Was this translation helpful? Give feedback.
-
It turns out that httpx.Request can be pickled but loading the serialized byte code will not return the same object at all.
I did not a lot of research on it so far and I cannot tell were exactly the problem occurs in httpx.
Reason for pickling is, that I'm running the client in several child processes and this leads to strange errors like
httpx.StreamClosed: Attempted to read or stream content, but the stream has been closed.
At least some warning should be given, that this class is not safe to pickle even if you can pickle it.
Beta Was this translation helpful? Give feedback.
All reactions