How to debug tasks
Since the uwsgi uses the spooler processes, debugging the task execution in these process requires a hack through remote debugging.
The following procedure works in pyCharm IDE.
pip install pydevd-pycharm==191.6605.12
(versions must be upgraded, see preferences/about)open a shell in the virtual environment and prepare this command with the following set of arguments:
uwsgi --http=:8000 --master \ --chdir=/Users/gu/Workspace/django-uwsgi-taskmanager/demo \ --static-map /static=./static \ --module=demo.wsgi --callable=application \ --pythonpath=/Users/gu/Workspace/django-uwsgi-taskmanager/demo \ --processes=2 \ --spooler=./spooler --spooler-processes=1
define a python remote debug configuration on pycharm, using localhost:4444 as host:port
add this snippet of code right before the point you want the execution to break
import pydevd pydevd.settrace('localhost', port=4444, stdoutToServer=True, stderrToServer=True)
use
wsgi.py
to debug the request/response processes andtaskmanager/models.py
ortaskmanager/tasks.py
, to debug the command executionadd breakpoints
launch the uwsgi command in terminal
launch the debugger in pycharm
navigate the admin UI, create and launch the task
debug!
When no debugger is activated, this can be used to test the uwsgi-spooler in a local development environment. Just remove the code snippets and launch the uwsgi command from the terminal.
You’ll be able to manage tasks and execute the commands using the uwsgi spooler processes.