I'm on PyCharm 2018.1 and I am trying to debug a local process that utilizes monkey patching by Gevent. I have enabled Gevent support in the IDE, however I still cannot attach. Whenever I try to attach to the process, I get the following stack, at which point pydevd in PyCharm exits with code 0.
Traceback (most recent call last):
File "/path/lib/python3.6/site-packages/pycharm-debug-py3k.egg/_pydevd_bundle/pydevd_comm.py", line 539, in start_client
File "/path/lib/python3.6/site-packages/gevent/_socket3.py", line 290, in connect
r = getaddrinfo(address, address, self.family)
File "/path/lib/python3.6/site-packages/gevent/_socketcommon.py", line 288, in getaddrinfo
return get_hub().resolver.getaddrinfo(host, port, family, type, proto, flags)
File "/path/lib/python3.6/site-packages/gevent/resolver_thread.py", line 65, in getaddrinfo
return self.pool.apply(_socket.getaddrinfo, args, kwargs)
File "/path/lib/python3.6/site-packages/gevent/pool.py", line 325, in apply
return self.spawn(func, *args, **kwds).get()
File "/path/lib/python3.6/site-packages/gevent/event.py", line 382, in get
File "/path/lib/python3.6/site-packages/gevent/event.py", line 106, in _wait_core
result = self.hub.switch()
File "/path/lib/python3.6/site-packages/gevent/hub.py", line 629, in switch
File "/path/lib/python3.6/site-packages/gevent/hub.py", line 633, in switch_out
raise BlockingSwitchOutError('Impossible to call blocking function in the event loop callback')
gevent.hub.BlockingSwitchOutError: Impossible to call blocking function in the event loop callback
I saw this bug thread, but it pertains to remote debugging. In my case I have a local process to attach to.
Surprisingly, adding these 3 lines right before monkey.patch_all() does allow me to attach the debugger, although the process a little weird: when a breakpoint is hit, all gevent loops pause.
os.environ["GEVENT_SUPPORT"] = "True"
I do have "Suspend=Thread" instead of All set. I am not sure why all threads pause - that does not seem like expected behavior.
Is there a more reasonable way to work around all of this without requiring very specific imports, or pausing all threads? I would have thought Gevent Support being set in the IDE would work fine.