不能腌制_螺纹锁紧使用WebService时的对象

2024-10-03 17:20:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python3.6

我尝试从下面显示的名为SubmitJobsUsingMultiProcessing()的类方法内部使用多处理,该方法进一步依次调用另一个类方法。在

我一直遇到这样的错误:类型错误:无法pickle_螺纹锁紧物体。在

我不知道这意味着什么。我怀疑下面这一行试图建立与webserverapi的连接可能是原因,但我完全不知道为什么。在

我不是一个合适的程序员(代码作为一个项目组合建模团队的一部分),所以如果这是一个明显的问题,请原谅我的无知和许多事先感谢。在

import multiprocessing as mp,functools

def SubmitJobsUsingMultiProcessing(self,PartitionsOfAnalysisDates,PickleTheJobIdsDict = True):
    if (self.ExportSetResult == "SUCCESS"):
        NumPools = mp.cpu_count()
        PoolObj =  mp.Pool(NumPools)   
        userId,clientId,password,expSetName = self.userId , self.clientId , self.password , self.expSetName
        PartialFunctor = functools.partial(self.SubmitJobsAsOfDate,userId = userId,clientId = clientId,password = password,expSetName = expSetName)
        Result = PoolObj.map(self.SubmitJobsAsOfDate, PartitionsOfAnalysisDates)
        BatchJobIDs = OrderedDict((key, val) for Dct in Result for key, val in Dct.items())
        f_pickle = open(self.JobIdPickleFileName, 'wb')
        pickle.dump(BatchJobIDs, f_pickle, -1)
        f_pickle.close()


 def SubmitJobsAsOfDate(self,ListOfDatesForBatchJobs,userId,clientId,password,expSetName):

    client = Client(self.url, proxy=self.proxysettings)
    if (self.ExportSetResult != "SUCCESS"):
        print("The export set creation was not successful...exiting")
        sys.exit()

    BatchJobIDs = OrderedDict()
    NumJobsSubmitted = 0
    CurrentProcessID = mp.current_process()

    for AnalysisDate in ListOfDatesForBatchJobs:
        jobName = "Foo_" + str(AnalysisDate)
        print('Sending job from process : ', CurrentProcessID, ' : ', jobName)
        jobId = client.service.SubmitExportJob(userId,clientId,password,expSetName, AnalysisDate, jobName, False)
        BatchJobIDs[AnalysisDate] = jobId
        NumJobsSubmitted += 1

        'Sleep for 30 secs every 100 jobs'
        if (NumJobsSubmitted % 100 == 0):
            print('100 jobs have been submitted thus far from process : ', CurrentProcessID,'---Sleeping for 30 secs to avoid the SSL time out error')
            time.sleep(30)
    self.BatchJobIDs = BatchJobIDs
    return BatchJobIDs

以下是轨迹:

^{pr2}$

Tags: 方法inselfforifmppasswordpickle
1条回答
网友
1楼 · 发布于 2024-10-03 17:20:16

我正为一个类似的问题而挣扎。<;=3.5中存在一个错误,其中_螺纹锁紧对象在pickle(不能)时没有引发错误,Pool对象必须从主进程传递给它一个函数和参数,这依赖于pickle(pickling是序列化对象的一种方法)在我的例子中RLock对象在日志模块中的某个地方。我怀疑你的代码在3.5上能正常工作。祝你好运。见this bug resolution.

相关问题 更多 >