Skip to content

Commit

Permalink
Merge pull request #37 from samchrisinger/master
Browse files Browse the repository at this point in the history
Add section on using PyCharm remote debugger
  • Loading branch information
sloria committed Dec 21, 2015
2 parents 777722a + 83711c4 commit d94f0f2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/osf/common_problems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,45 @@ If invoking assets or server commands throw an error about uritemplate, run the
pip install uritemplate.py==0.3.0

and then re run the command that failed.

Using PyCharm's Remote Debugger
*******************************

Some debugging tasks make it difficult to use the standard debug tools (i.e. pdb, ipdb, or PyCharm's debugger).
Usually this is becuase you're running code in a way where you don't have ready access to the process's
standard in/out. Examples of this include:

- celery tasks
- local testing/debugging using uWSGI

One way to debug code running in these kinds of enviornments is to use the PyCharm remote debugger. Follow the
JetBrains documentation for creating a new run configuration for the remote debugger: https://www.jetbrains.com/pycharm/help/remote-debugging.html. At some point you may be required to add pycharm-debug.egg to your system's PYTHONPATH. The
easist way to do this is to modify your ~/.bash_profile to automatically append this module to the python path. This looks like:

::

export PYTHONPATH="$PYTHONPATH:<your_path_to>/pycharm-debug.egg"

To apply these changes to the current bash session, simply

::

source ~/.bash_profile

When you start the remote debug server in PyCharm you will get some console output like:

::

Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('localhost', port=54735, stdoutToServer=True, stderrToServer=True)

So to use, simple copy paste the bottom two lines wherever you need to run a debugger. In celery tasks for example,
this often means inside a task definition where it would be otherwise impossible to step into the code. Trigger
whatever is needed to queue the celery task, and watch the PyCharm console to see when a new connection is initiated.

Happy remote-debugging.




0 comments on commit d94f0f2

Please sign in to comment.