Monkey-patching vs. PyCharm Debugger

In PyCharm, programs with monkey patching enabled cannot be debugged. The debugger says Connecting, then Disconnecting about a second later. Here is a simple example to demonstrate the problem:

from gevent import monkey; monkey.patch_all()

import DNS; DNS.DiscoverNameServers()

def getMX(url):

    mx_hosts = DNS.mxlookup(url);

    print mx_hosts, '(', url, ')'

if __name__ == '__main__':


1 comment
Comment actions Permalink

Until Jetbrains fixes this, I found an easy workaround. Just paste the following at the top of your file (in your PyCharm installation directory):

# Support debugging gevent monkey-patched apps when gevent is installed from pydevd_constants import * #@UnusedWildImport try:     from gevent import monkey     monkey.patch_all() except ImportError:     pass


Please sign in to leave a comment.