Originally opened by @cloasdata on 2022-04-24 18:04:17 in encode/httpx
importpickleimporttracebackimporthttpxclassMyExtension:
some_stuff="stuff"url="https://github.com"method="GET"extensions= {"a_proper_extension": MyExtension()}
request=httpx.Request(method, url, extensions=extensions)
print(request)
pickled_request=pickle.dumps(request)
print(pickled_request)
repickled_request=pickle.loads(pickled_request)
print(repickled_request)
try:
assertrepickled_request==request# is not the same but should be equalexceptAssertionErrorase:
print(traceback.format_exc())
print("extensions:", repickled_request.extensions) # gone! whyIt 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.
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.