Skip to content

Profiling once active/enabled cannot be deactivated/disabled #614

@misyntropy

Description

@misyntropy

In my script, I use profiling to keep track:

if __name__ == '__main__':
    pr = Profile()
    pr.enable()
    #...
    #My code
    #...
    pr.disable()
    s = io.StringIO()
    sortby = pstats.SortKey.CUMULATIVE
    ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    ps.print_stats()
    ps.dump_stats("../run.prof")

If I encounter an error and this script doesn't run to completion, and I try to run again (after fixing the problem but that's not required here), I encounter this error at the pr.enable() line.

ValueError: Another profiling tool is already active

At this point, even if I run pr.disable() or even del pr, this error never goes away. The only thing that works is to restart the kernel itself.

Is this a bug? Is this a bad practice that I should not do (if so, what's the standard practice?)?

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