Python 当任何线程中出现异常时,多处理池挂起

Python 当任何线程中出现异常时,多处理池挂起,python,exception,multiprocessing,pool,freeze,Python,Exception,Multiprocessing,Pool,Freeze,我是Python新手,尝试使用multiprocessing.pool程序来处理文件,只要没有异常,它就可以正常工作。如果任何线程/进程出现异常,整个程序将等待该线程 代码片段: cp = ConfigParser.ConfigParser() cp.read(gdbini) for table in cp.sections(): jobs.append(table) #print jobs poolreturn = pool.map(worker, jobs) pool.close()

我是Python新手,尝试使用multiprocessing.pool程序来处理文件,只要没有异常,它就可以正常工作。如果任何线程/进程出现异常,整个程序将等待该线程

代码片段:

cp = ConfigParser.ConfigParser()
cp.read(gdbini)
for table in cp.sections():
    jobs.append(table)
#print jobs
poolreturn = pool.map(worker, jobs)
pool.close()
pool.join()
失败消息:



但它仍在等待,不确定遗漏了什么。

我也有同样的问题。当工作进程引发具有自定义构造函数的用户异常时,就会发生这种情况。确保您的异常(在这种情况下为ConfigParser.NoOptionError)使用两个参数准确地初始化基本异常:

class NoOptionError(ValueError):

    def __init__(self, message, *args):
        super(NoOptionError, self).__init__(message, args)

在Python3.2+中,这与预期一样有效。对于Python2,这个错误在r74545中已经修复,将在Python2.7.3中提供。同时,您可以使用
configparser
库,它是3.2+版本中configparser的一个后端口

此异常来自Python模块(ConfigParser),需要在该模块中修复。看起来ConfigParser与SQLAlchemy存在相同的问题(异常不可pickle),请参阅。我将此问题报告为。这是configparser还是多进程中的一个大问题?(我在多进程中遇到了相同的错误,与configparser无关)
try:
    ifile=cp.get(table,'inputfilename')
except ConfigParser.NoSectionError,ConfigParser.NoOptionError:
    usage("One of Parameter not found for"+ table)
    terminate()
class NoOptionError(ValueError):

    def __init__(self, message, *args):
        super(NoOptionError, self).__init__(message, args)