I'm developing a flask.app 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.
5 Answers
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:
/Users/iandouglas/.virtualenvs/defaultenv/bin/gunicorn
Set the "Script Parameters" to something like
-b 192.168.1.1:9000 app:yourappname
(assuming your primary starting script is called app.py 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 0.0.0.0:5001
parameter to force gunicorn to bind to all IPs on my machine on port 5001.
p.s.
One important step is to add this envvar as pointed out here
PYDEVD_USE_CYTHON=NO

- 33,193
- 69
- 233
- 372

- 4,146
- 2
- 33
- 33
-
In PyCharm 2.7.3 under `Settings > Project Settings > Python Debugger` are only two options: "Attach to subprocess automatically while debugging" and "Collect run-time types information for code insight". Did you installed additional plugins? – arbyter Dec 25 '13 at 10:34
-
No, I've always had "gevent compatible debugging" in my editor, both v2 and v3. I do use the Professional edition... perhaps they don't include it in the free Community Edition. – iandouglas Jan 04 '14 at 05:35
-
3Version 3.4 of the CE has `Gevent compatible debugging` next to the other two options @arbyter mentioned. – ᴠɪɴᴄᴇɴᴛ Oct 25 '14 at 13:23
-
Thanks alot for that! How simple was that! – Codious-JR Mar 03 '17 at 13:18
-
7this is an old post, but helpful for some people still. If while debugging, the process suddenly restarts, it's because of gunicorn worker timeout. You can set it higher for longer debugging time, use `--timeout INT` to your script parameters. – rrw Aug 31 '17 at 02:50
-
1This doesn't appear to be working in recent versions. Execution is not stopped at the breakpoints in my case – Eldamir Dec 11 '17 at 08:25
-
I was able to load my gunicorn config file. Instead of the param `-b 192.168.1.1:9000`, I just gave the param `-c
` – Vikas Prasad Feb 16 '18 at 06:02 -
for future reader: if you wish to set envs in bulk: https://stackoverflow.com/a/42708476/1781024 – Vikas Prasad Jun 16 '20 at 07:21
-
I have same issue with @Eldamir ie cannot get the breakpoints working ie can Run but cannot Debug (it gets hang) – Nam G VU Dec 25 '20 at 11:33
-
how would this work for a project in a docker on your local machine (mac if it makes a difference) – JonYork Feb 05 '21 at 01:23
My case for PyCharm 2018.1.3 Professional:
Go to run/debug configurations creating-and-editing-run-debug-configurations
Choose new "Python" config
- Script path: your_path_to_/venv/bin/gunicorn
- Parameters(for my case):
-b :5001 --access-logfile - --error-logfile - "run:create_application()"
- Python interpreter: your venv python version for project
- Working directory: path to your project
- Save and press DEBUG (Shift+F9)
- be happy!

- 631
- 7
- 11
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.
PYDEVD_USE_CYTHON=NO

- 1,191
- 1
- 14
- 16
The accepted solution works for me, but I was facing myproject module not found error, which was solved by using:
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
Pycharm ✅
instead of
gunicorn --bind 0.0.0.0:8000 'myproject.wsgi:application'
Pycharm ❌

- 461
- 3
- 13
- edit your flask launch python file
$ vim manage.py
- remove debug option setting
from web import app
import sys
if __name__ == '__main__':
# app.run(host='0.0.0.0', port=app.config["PORT"], debug=app.config["DEBUG"])
app.run(host='0.0.0.0', port=9998, debug=False)

- 61
- 2