使用Google App Engine时,PyCharm Professional调试器存在一个问题。调试由我的代码手动启动的线程时,断点不起作用
这会影响调试dev_appserver
上运行的代码的能力,该代码使用threading.Thread
或concurrent.futures.ThreadPoolExecutor
2.7 backport(现在GAE正式支持)
问题出现在PyCharm 2017.2和2017.3.4中。 在Ubuntu Linux上观察GAE SDK 1.9.66。
这是一个repro代码 - 从任何请求处理程序调用它。
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()
答案 0 :(得分:3)
快速解决方法是修补patch_threads
行<pycharm-folder>/helpers/pydev/pydevd.py
附近的978
功能,并为单独的GAE模块添加settrace:
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()