Using statprof to profile a Django view - cannot use signals in a stream

statprof is a statistical profiling tool for Python. Documents say that it can only be used to profile the main thread. Therefore, if you use it to profile some function that is called during a processing request when used ./manage.py runserver, it raises a ValueError: the signal only works in the main thread.

I see two possible ways to solve this problem (in addition to calling the function from the console, which is possible, but not so convenient):

1) Hack statprof so that it does not use signals - but it is not obvious how to do it, or if it is possible at all.

2) Setting the runerver command starts everything in the main thread.

Perhaps there are other solutions? Has anyone used statprof in a django view?

+3
source share
1 answer

If you ./manage.py runserver --noreloaduse statprof when using it, it will start the development server in one thread and will manage this problem.

0
source

All Articles