在pycharm中使用多处理时如何调试 [英] How to debug when using multiprocessing in pycharm

查看:102
本文介绍了在pycharm中使用多处理时如何调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 pycharm 社区版中使用 anaconda2 调试多进程程序.它有几个后台工作进程.工作进程将检查输入队列以检索任务,直到接收到任务为止.其实我只对主进程感兴趣.但是pycharm调试器总是步入子进程,好像主进程一直没有工作,任务一直没有发出.如何使调试器脱离子进程?工作子进程如下所示:

I am debugging a multiprocess program with anaconda2 in pycharm community edition. It has several background worker processes. The worker process will check the input Queue to retrieve the task without sleep until a task received. In fact, I'm only interested in the main process. But the pycharm debugger always step into the subprocess, it seems that the main process hasn't been working, and the task never sent out. How can I make the debugger out of the subprocess? The worker subprocess looks like this:

class ILSVRC_worker:

...

def run(self):
    cfg_parser = ConfigParser.ConfigParser()
    cfg_parser.read(self.cfg_path)
    data_factory = ILSVRC_DataFactory(cfg_parser)
    logger = mp.log_to_stderr(logging.INFO)
    while True:
        try:
            annotation_path = self.que_in.get(True,0.1)
        except Queue.Empty:
            continue
        if annotation_path is None:
            # to exit the subprocess
            logger.info('exit the worker process')
            break
        ...

推荐答案

我可以想到两种方法来实现这一点,但不幸的是,我认为社区版无法实现.

I could think of two ways to achieve this but unfortunately I think it won't be possible with the community edition.

  • 如果您有进程的 PID,您可以尝试使用工具">附加到进程.."功能(我不知道社区版是否提供该功能)来附加到它.如果您使用 Pool,这会很困难,因为您不知道将作业分配给哪个进程.
  • 另一种方法是使用远程调试器并在分派的 python 进程中连接到它.这仅在专业版中可用
  • If you have the PID of the process you could try attaching to it by using the Tools>Attach to Process.. functionality (I don't know if that is available in the community edition). This is difficult if you use a Pool because you don't know which process the job is assigned to.
  • Another way would be to use a remote debugger and connect to it in the dispatched python process. This is only available in the professional edition

我最终在没有任何多处理的情况下测试了我的代码

I ended up testing my code without any multiprocessing

这篇关于在pycharm中使用多处理时如何调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆