Skip to content
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

Nested profiling with cProfile raises exception in Python 3.12. #110770

Closed
manueljacob opened this issue Oct 12, 2023 · 1 comment
Closed

Nested profiling with cProfile raises exception in Python 3.12. #110770

manueljacob opened this issue Oct 12, 2023 · 1 comment
Labels
pending The issue will be closed if no feedback is provided stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@manueljacob
Copy link

manueljacob commented Oct 12, 2023

Bug report

Bug description:

import cProfile

p1 = cProfile.Profile()
p1.enable()

p2 = cProfile.Profile()
p2.enable()

In Python 3.11 this used to pass, but in Python 3.12 the last line raises “ValueError: Another profiling tool is already active”.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

@manueljacob manueljacob added the type-bug An unexpected behavior, bug, or error label Oct 12, 2023
@gaogaotiantian
Copy link
Member

This is a delibrate change, well you can call it a breaking change, but it's not a bug.

Nested profiler never (really) works in Python, the code you give is more like a "don't do this" example. It is equivalent (in Python 3.11) to

import cProfile

p1 = cProfile.Profile()
p1.enable()

p2 = cProfile.Profile()
# p1 is silently disabled here
p1.disable()
p2.enable()

That's not nested, that's just sequential profiling with two profilers - and if you really want to do that, you should be explicit!

A nested profiler should either

  • Be able to log what happens in the inner profiler from the outer profiler(which it can't)
  • Or at least for the outer profiler to continue to work after the inner profiler finishes(which it can't either)

Yes, the code given won't "report an error" in Python 3.11, but it also won't behave expectedly, it just keeps its mouth shut. I'd consider an error for "this is not how it's going to work!" as an improvement :)

@gaogaotiantian gaogaotiantian added stdlib Python modules in the Lib dir pending The issue will be closed if no feedback is provided labels Oct 12, 2023
@manueljacob manueljacob changed the title Nested profiling with cProfile stopped working in Python 3.12. Nested profiling with cProfile raises exception in Python 3.12. Oct 12, 2023
@iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending The issue will be closed if no feedback is provided 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