Skip to content

cProfile cannot run code that pickles objects defined in __main__ #132737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aneeshdurg opened this issue Apr 19, 2025 · 0 comments
Open

cProfile cannot run code that pickles objects defined in __main__ #132737

aneeshdurg opened this issue Apr 19, 2025 · 0 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@aneeshdurg
Copy link

aneeshdurg commented Apr 19, 2025

Bug report

Bug description:

import pickle
import sys
from dataclasses import dataclass, field


@dataclass
class State:
    x: list[int] = field(default_factory=list)

print(pickle.dumps(State([0])))

The following code will run successfully on it's own, but will fail if run with cProfile, with the message that __main__.State could not be found by.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@aneeshdurg aneeshdurg added the type-bug An unexpected behavior, bug, or error label Apr 19, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Apr 19, 2025
@gaogaotiantian gaogaotiantian self-assigned this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants