1

基于使用 pathos 和 dill 的示例多进程,我遇到了 cPickle 错误。我像www3cam那样做;加上一点点……通过删除 pathos、dill、multiprocess 和 pyreadline。然后pip install pathos --no-cache-dir小心地删除上面提到的那些侧包后点击。全新安装、冷重启 PC 以及稍后更新 Anacoda2……装有 cPickles 的罐子……还在,Frank Zappa 继续唱着他的“Titties and Beer”歌曲。

修改后的代码1

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, sys
import datetime, time
import multiprocessing
import pathos.pools as pp
import dill


class Multiprocess(object):

    def __init__(self):
        pass

    def qmp_worker(self,(inputs, the_time)):
        print " Processs %s\tWaiting %s seconds" % (inputs, the_time)
        time.sleep(int(the_time))
        print " Process %s\tDONE" % inputs

    def qmp_handler(self):                           # Non tandem pair processing
        pool = pp.ProcessPool(2)
        pool.map(self.qmp_worker, data)

def mp_worker((inputs, the_time)):
    print " Process %s\tWaiting %s seconds" % (inputs, the_time)
    time.sleep(int(the_time))
    print " Process %s\tDONE" % inputs
    sys.stdout.flush()

def mp_handler():                           # Non tandem pair processing
    p = multiprocessing.Pool(2)
    p.map(mp_worker, data)

def mp_handler_tandem():
    subdata = zip(data[0::2], data[1::2])
#    print subdata
    for task1, task2 in subdata:
        p = multiprocessing.Pool(2)
        p.map(mp_worker, (task1, task2))

#data = (['a', '1'], ['b', '2'], ['c', '3'], ['d', '4'])
data = (['a', '2'], ['b', '3'], ['c', '1'], ['d', '4'], 
        ['e', '1'], ['f', '2'], ['g', '3'], ['h', '4'])

if __name__ == '__main__':
    sys.stdout.flush()
#    print 'mp_handler():'
#    mp_handler()
#    print '---'
#    time.sleep(2)

#    print '\nmp_handler_tandem():'
#    mp_handler_tandem()
    print '---'
#    time.sleep(2)

    Multiprocess().qmp_handler()

也许应该像这里的示例“捕获和打印 PyQt5 回溯?

下面的代码片段让我思考和好奇是否必须为莳萝做类似的事情?

# Back up the reference to the exceptionhook
sys._excepthook = sys.excepthook

# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook

最新错误:

文件“c:\python\anac2\lib\site-packages\pathos\multiprocessing.py”,第 137 行,在地图中 return _pool.map(star(f), zip(*args)) # chunksize File “c:\ python\anac2\lib\site-packages\multiprocess\pool.py”,第 251 行,在 map 中返回 self.map_async(func, iterable, chunksize).get() 文件“c:\python\anac2\lib\site- packages\multiprocess\pool.py",第 567 行,在 get raise self._value cPickle.PicklingError: Can't pickle : attribute lookup builtin .function failed

有关此错误的更多信息位于:我的 cPickle 转储

4

0 回答 0