django-debug-toolbar: Profiler raises ValueError in Python 3.12

Enabling the profiling panel in Python 3.12 and Django 5.0.1 causes the following exception:

   File "/usr/local/lib/python3.12/site-packages/debug_toolbar/panels/profiling.py", line 144, in process_request
     return self.profiler.runcall(super().process_request, request)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/local/lib/python3.12/cProfile.py", line 109, in runcall
     self.enable()
 ValueError: Another profiling tool is already active

This is due to a change in Python 3.12: https://github.com/python/cpython/issues/110770

There is also some relevant discussion of the same issue over on the django-silk repo which may be helpful in finding a way forward: https://github.com/jazzband/django-silk/issues/682

About this issue

  • Original URL
  • State: open
  • Created 5 months ago
  • Reactions: 3
  • Comments: 18 (15 by maintainers)

Most upvoted comments

@elineda Adding –nothreading to the runserver command does seem to resolve the issue for me.

I am running my development server through Uvicorn though, so I am curious if you know a solution for that as well?

@elineda Adding –nothreading to the runserver command does seem to resolve the issue for me.

I am running my development server through Uvicorn though, so I am curious if you know know a solution for that as well?

Nan no way, uvicorn doesn’t accept thread value

Ok seem the problem occurs only the two requests are send on the runserver in the same times. Using a debuger like pycharm one is not necessary. That’s strange because runserver only do one request at the time. Need to find one profiler open even if the other is not finished