I am trying to use a middleware to profile a WSGI application. This middleware uses plop which is a low overhead profiler for python that relies on the signal module.
If I run a Django app which uses this middleware by running ./manage.py runserver --forked then it middleware works as expected. However when the same Django app is running on apache via mod_wsgi then it does not work as intended.
The mod_wsgi instance is configured with WSGIRestrictSignal Off and WSGIDaemonProcess example processes=5 threads=1 and when the Django app is run the following error occurs:
ValueError: signal only works in main thread
This is the same error that occurs if I run the development server without the --forked flag. I don’t think it should be occurring with apache because the number of threads is 1.
What can I do to fix this?
Using a background thread which does a sleep() between samples should technically work and have used that approach before when have done this myself.
There is an example of creating a background thread for this purpose in:
http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Extracting_Python_Stack_Traces