Skip to content

Client objects are not pickle-able for multiprocess programs #837

@XuehaiPan

Description

@XuehaiPan

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

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. It would be nice if we let all classes in the openai package be pickle-able。

To Reproduce

  1. Create an OpenAI or AsyncOpenAI client.
  2. Serialize the client using the pickle module.

Code snippets

import pickle

from openai import OpenAI, AsyncOpenAI


client = OpenAI(api_key='sk-...')
async_client = AsyncOpenAI(api_key='sk-...')

pickle.dumps(client)  # TypeError: cannot pickle '_thread.RLock' object
pickle.dumps(async_client)  # TypeError: cannot pickle '_thread.RLock' object

OS

macOS

Python version

Python 3.11.6

Library version

openai v1.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions