Django gunicorn debug

First, I had a Django application with the testing server turned on. To debug this setting, I can simply add import pdb; pdb.set_trace() import pdb; pdb.set_trace() anywhere in the code and have a breakpoint that throws me into the interactive debugger in the terminal (on the command line).

I recently switched to a machine gun to get some benefits. How can I get similar behavior when using this Gunicorn setting. I tried setting the dismissal settings using debug=True and daemon=False , but this will not work.

Anyone have a solution?

+7
source share
5 answers

To run the green unicorn in the reverse proxy configuration (under nginx) in debug / debug mode, enter the following parameters in PyCharm Run / Django / Edit:

Of course, use any port (instead of 7777 ) that you configured nginx for the proxy.

Screenshothot

+4
source

Well, I recently ran into a similar problem. I was unable to apply the @dudklein solution (I get I / O errors when the debugger tried to execute input - ipdb, pdb, etc.)

I used python remote debbuger - winpdb and built-in debugging .

  • install winpdb in your virtualenv

     pip install winpdb 
  • import and run the built-in debugger in your code:

     import rpdb2 rpdb2.start_embedded_debugger('pass') 
  • run gunicorn with the argument --timeout

     gunicorn -t 3600 env:application 
  • launch a proper browser view, for example. http://127.0.0.1:8000/your-view/

  • connect to the built-in debugger using winpdb:

     winpdb -a /path/to/django/app/views.py 

    It will ask you for a password (use the one that you set in your code, in my example it is "pass") and run a nice graphical interface with a debugger.

  • If you need a tutorial for winpdb - here you are .

enter image description here

+3
source

If you can start gunicorn by specifying an application instance that is an instance of the DebuggedApplication class from the werkzeug library, you can set breakpoints using the werkzeug debugger using import ipdb; ipdb.set_trace() import ipdb; ipdb.set_trace() directly in your browser.

 import django.core.handlers.wsgi from werkzeug.debug import DebuggedApplication application = django.core.handlers.wsgi.WSGIHandler() application = DebuggedApplication(application, evalex=True) 

Make sure you install the werkzeug and ipdb library of course. ( pip install werkzeug and pip install ipdb )

+2
source

Now I managed to use gunicron with djnago and ipdb.

run python -m ipdb manage.py run_gunicorn --debug -t 3600

I am using Django 1.4 and gunicorn 0.16.1. then you can usually use import ipdb; ipdb.set_trace() import ipdb; ipdb.set_trace() in the code. No need for the werkzeug library.

I am trying to debug a facebook application, so I can’t use the build on the development server because facebook is trying to use SSL and the dev server just cannot respond normally.

While I was looking for a solution, I found a pdb message : using Python debugger in Django suggesting to run python -m pdb manage.py runserver all the time. Although this is not necessary for the django dev server, I decided to try it with gunicordn and ipdb, and it worked.

+2
source

What I finally finished, run python manage.py runserver <your_external_IP>:8000 when I want to use pdb .

So, you need to have 2 different repositories on the same machine, one of which is the LIVE production assembly (one works with gunicorn ), and the other is the TEST assembly, which I need to debug where I use pdb , When the situation is stable when building TEST, I combine a TEST branch with a LIVE branch . No development or changes occur on the LIVE branch so I avoid merge conflicts.

Hope this helps others who are addicted to pdb ;)

0
source

All Articles