How to debug with pycharm 2.x that's running on gunicorn


I’m developing a that uses web socket functionality and installed flask-socket to provide that. So the flask-socket developer recommends gunicorn as web server. My question is now how to connect the remove debugger of pycharm with gunicorn to intercept the execution with breakpoints.

Asked By: arbyter



Settings > Project Settings > Python Debugger

There’s an option in there to enable "gevent compatible debugging".

Then, go into your debugger settings (shortcut is through the toolbar, click the dropdown near the play/debug icons and select "Edit Configurations"

Set the "Script" to your virtualenv’s isntallation of gunicorn, something like:


Set the "Script Parameters" to something like
-b app:yourappname (assuming your primary starting script is called and you’re refering to it as ‘yourappname’

the "Working directory" will be automatically set otherwise set it to wherever your code lives: /Users/iandouglas/PycharmProjects/MyExampleApp

I have a separate config file for my gunicorn settings, which specifies a host/port but I still had to specify the -b parameter to force gunicorn to bind to all IPs on my machine on port 5001.


One important step is to add this envvar as pointed out here

Answered By: iandouglas
  • edit your flask launch python file
$ vim
  • remove debug option setting
from web import app
import sys

if __name__ == '__main__':
    #'', port=app.config["PORT"], debug=app.config["DEBUG"])'', port=9998, debug=False)
Answered By: Binhong Wu

My case for PyCharm 2018.1.3 Professional:

  1. Go to run/debug configurations

  2. Choose new “Python” config

  3. Script path: your_path_to_/venv/bin/gunicorn
  4. Parameters(for my case): -b :5001 --access-logfile - --error-logfile - "run:create_application()"
  5. Python interpreter: your venv python version for project
  6. Working directory: path to your project
  7. Save and press DEBUG (Shift+F9)
  8. be happy!
Answered By: MrNinjamannn

I was trying to debug on Pycharm 2020.2.1 and the break points weren’t correctly working even though the Gevent compatible debugging was enabled. It turned out that I had to disable Cython for my run configuration via setting the environment variable as described here to make it work.

Answered By: Philipp
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.