用于多处理的python调试工具 [英] python debug tools for multiprocessing

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

问题描述

我有一个python脚本可以处理线程,进程和数据库的连接。
当我运行我的脚本时,python崩溃。



我无法显式检测出这种情况。



现在我正在寻找工具来获取更多的信息,当python崩溃,
或查看器,以查看我所创建的所有进程/连接。

解决方案

我创建了一个模块 RemoteException.py ,显示完整的追溯在一个过程中是例外。 Python2。 下载,并将其添加到您的代码中:

  import RemoteException 

@ RemoteException.showError
def go():
raise异常('Error!')

如果__name__ =='__main__':
导入多处理
p = multiprocessing.Pool(processes = 1)
r = p.apply(go)#full tr​​aceback显示在这里

OLD ANSWER



我也有问题。



这是我做的...一个RemoteException调试多处理调用



RemoteException.py



复制源代码并删除第19行:
file.write('\\\
in%s'%(Process.thisProcess,))

和行
import Process



问题是:加工只转移异常,但丢失了追溯。
下面的代码创建一个保存回溯的异常对象。并在打电话过程中进行打印。



在脚本中,您可以执行以下操作:

  import RemoteException 

def f():
try:
#这里是失败的代码,但你不知道
通过
除了:
ty,err,tb = RemoteException.exc_info()#like sys.exc_info但是更好的消息
raise ty,err,tb

#您的多处理调用f


I have a python script that works with threads, processes, and connections to a database. When I run my script, python crashes.

I cannot explicitly detect the case in which this happens.

Now I am looking for tools to get more information when python crashes, or a viewer to see all my created processes/connections.

解决方案

I created a module RemoteException.py that shows the full traceback of a exception in a process. Python2. Download it and add this to your code:

import RemoteException

@RemoteException.showError
def go():
    raise Exception('Error!')

if __name__ == '__main__':
    import multiprocessing
    p = multiprocessing.Pool(processes = 1)
    r = p.apply(go) # full traceback is shown here

OLD ANSWER

I had the problem, too.

this is what i did... a RemoteException to debug multiprocessing calls

RemoteException.py

copy the source and remove line 19: file.write('\nin %s ' % (Process.thisProcess,)) and the line import Process

The problem is: multiprocessing only transfers the exception but looses the traceback. The code below creates an Exception object that saves the traceback. And prints it in the calling process.

In your script you can do something like this:

import RemoteException

def f():
    try:
        # here is code that fails but you do know not where
        pass
    except:
        ty, err, tb = RemoteException.exc_info() # like sys.exc_info but with better message
        raise ty, err, tb

# here follows your multiprocessing call to f

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

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