Reputation: 700
PyCharm Professional debugger has one issue when working with Google App Engine. Breakpoints do not work when debugging Threads launched manually by my code.
This affects ability to debug code running on dev_appserver
which uses threading.Thread
or concurrent.futures.ThreadPoolExecutor
2.7 backport (which is officially supported by GAE now)
The issue occurs both in PyCharm 2017.2 and 2017.3.4. Observed on GAE SDK 1.9.66 on Ubuntu Linux.
Here is a repro code - call this from any request handler.
from concurrent.futures import ThreadPoolExecutor, wait
from threading import Thread
def worker():
logging.info("Worker") # set breakpoint here
time.sleep(3)
def call_this(): # call this from your request handler
tpe = ThreadPoolExecutor(max_workers=5)
futures = [tpe.submit(worker) for i in range(10)]
wait(futures)
threads = [Thread(worker) for i in range(10)]
for t in threads: t.start()
for t in threads: t.join()
Upvotes: 3
Views: 195
Reputation: 700
Quick fix is to patch patch_threads
function in <pycharm-folder>/helpers/pydev/pydevd.py
around line 978
and add settrace for the separate GAE's module:
def patch_threads(self):
try:
# not available in jython!
import threading
threading.settrace(self.trace_dispatch) # for all future threads
from google.appengine.dist27 import threading as gae_threading
gae_threading.settrace(self.trace_dispatch) # for all future threads
except Exception as e:
pass
from _pydev_bundle.pydev_monkey import patch_thread_modules
patch_thread_modules()
Upvotes: 3