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

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

Open
milindsmart opened this issue Jul 24, 2024 · 1 comment
Open

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

milindsmart opened this issue Jul 24, 2024 · 1 comment

Comments

@milindsmart
Copy link

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?)?

@milindsmart
Copy link
Author

milindsmart commented Jul 24, 2024

Okay I skipped a couple of steps and hence may have filed this in the wrong location - I'm following the Spyder troubleshooting guide and I first got it in Spyder. Then I tried qtconsole and got the error there as well, which is why I opened this issue.

But just now I tried it in IPython and again got the error. So now I ran it in the Python interpreter using exec(open('mainrunner.py').read()) and still get the same problem - the profiling state cannot be disabled, reset, removed or anything else seemingly. Obviously running an entirely different instance of Python with python mainrunner.py does not show this problem.

What should I do? It feels like I'm doing something wrong here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant