X Tutup
The Wayback Machine - https://web.archive.org/web/20251205000651/https://github.com/python/cpython/issues/112144
Skip to content

Make http.cookiejar.CookieJar picklable #112144

@XuehaiPan

Description

@XuehaiPan

Bug report

Bug description:

I am developing a program that employs multiprocessing to enhance efficiency through parallel execution. Python relies on the pickle module for object serialization and inter-process communication. However, I've encountered an issue where the CookieJar object cannot be pickled due to its inclusion of an RLock object, which is causing problems in my application.

Here is the membership hierarchy:

openai.OpenAI -> httpx.Client -> httpx.Cookies -> http.cookiejar.CookieJar

Reproduce snippet:

# Add a code block here, if required

import pickle
from http.cookiejar import CookieJar


jar = CookieJar()
pickle.dumps(jar)  # TypeError: cannot pickle '_thread.RLock' object

We could implement a __reduce__ method for the CookieJar class to let it support serialization.

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup