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.

  1. pip install pydevd-pycharm==191.6605.12 (versions must be upgraded, see preferences/about)

  2. 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
    
  3. define a python remote debug configuration on pycharm, using localhost:4444 as host:port

  4. 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 and taskmanager/models.py or taskmanager/tasks.py, to debug the command execution

  5. add breakpoints

  6. launch the uwsgi command in terminal

  7. launch the debugger in pycharm

  8. navigate the admin UI, create and launch the task

  9. 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.