【问题标题】:Pycharm breakpoints on Thread for Google App Engine针对 Google App Engine 的 Thread 上的 Pycharm 断点
【发布时间】:2018-03-19 17:04:26
【问题描述】:

PyCharm Professional 调试器在使用 Google App Engine 时存在一个问题。调试由我的代码手动启动的线程时,断点不起作用。
这会影响调试在dev_appserver 上运行的代码的能力,该代码使用threading.Threadconcurrent.futures.ThreadPoolExecutor 2.7 反向端口(GAE 现在正式支持)

此问题同时出现在 PyCharm 2017.2 和 2017.3.4 中。 在 Ubuntu Linux 上的 GAE SDK 1.9.66 上观察到。

这是一个重现代码 - 从任何请求处理程序调用它。

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()

【问题讨论】:

    标签: google-app-engine pycharm pydev breakpoints dev-appserver


    【解决方案1】:

    快速修复是在<pycharm-folder>/helpers/pydev/pydevd.py 中围绕978 行修补patch_threads 函数,并为单独的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()
    

    【讨论】:

      猜你喜欢
      • 2010-10-26
      • 2015-04-21
      • 1970-01-01
      • 2011-04-09
      • 2013-05-18
      • 2011-10-04
      • 2015-10-01
      • 2010-11-03
      • 2014-02-26
      相关资源
      最近更新 更多