You can still run your WSGI app outside of uWSGI for development and debugging purposes.
However sometimes this is not possible, for example if your app relies on uWSGI API features.
As far as I know you can’t use “Attach to Process” from PyCharm because your WSGI app is running embedded into uWSGI, and there are no visible Python processes. Remote debugging however works like a charm.
-
Locate
pycharm-debug*.egg
files in your PyCharm distribution. For example, on OSX both can be found in/Applications/PyCharm.app/Contents
-
Copy
pycharm-debug-py3k.egg
next to your Flask app, or copypycharm-debug.egg
instead if you are using Python 2.7 -
In PyCharm, create a “Python Remote Debug” configuration from “Run/Debug Configurations” dialog. In this example I use
localhost
and port4444
. This dialog will show you the correspondingpydevd.settrace(...)
line. -
Add the following code to your app :
import sys sys.path.append('pycharm-debug-py3k.egg') # replace by pycharm-debug.egg for Python 2.7 import pydevd # the following line can be copied from "Run/Debug Configurations" dialog pydevd.settrace('localhost', port=4444, stdoutToServer=True, stderrToServer=True)
-
In PyCharm, start the remote debugging session. PyCharm’s console should display the following line :
Waiting for process connection...
-
Run your app from uWSGI as usual. It should attach to the debugger, and PyCharm’s console should display :
Connected to pydev debugger (build 139.711)
-
Your app should break on the
pydevd.settrace(...)
line. You can then continue and use PyCharm debugger as usual (breakpoints and so on)