<small id='rnBfp'></small><noframes id='rnBfp'>

      <tfoot id='rnBfp'></tfoot>
    1. <i id='rnBfp'><tr id='rnBfp'><dt id='rnBfp'><q id='rnBfp'><span id='rnBfp'><b id='rnBfp'><form id='rnBfp'><ins id='rnBfp'></ins><ul id='rnBfp'></ul><sub id='rnBfp'></sub></form><legend id='rnBfp'></legend><bdo id='rnBfp'><pre id='rnBfp'><center id='rnBfp'></center></pre></bdo></b><th id='rnBfp'></th></span></q></dt></tr></i><div id='rnBfp'><tfoot id='rnBfp'></tfoot><dl id='rnBfp'><fieldset id='rnBfp'></fieldset></dl></div>

        <legend id='rnBfp'><style id='rnBfp'><dir id='rnBfp'><q id='rnBfp'></q></dir></style></legend>
        • <bdo id='rnBfp'></bdo><ul id='rnBfp'></ul>

      1. 无法腌制 &lt;type 'instancemethod'&gt;使用

        时间:2023-05-25

          • <i id='jvtiH'><tr id='jvtiH'><dt id='jvtiH'><q id='jvtiH'><span id='jvtiH'><b id='jvtiH'><form id='jvtiH'><ins id='jvtiH'></ins><ul id='jvtiH'></ul><sub id='jvtiH'></sub></form><legend id='jvtiH'></legend><bdo id='jvtiH'><pre id='jvtiH'><center id='jvtiH'></center></pre></bdo></b><th id='jvtiH'></th></span></q></dt></tr></i><div id='jvtiH'><tfoot id='jvtiH'></tfoot><dl id='jvtiH'><fieldset id='jvtiH'></fieldset></dl></div>
              <bdo id='jvtiH'></bdo><ul id='jvtiH'></ul>

              <legend id='jvtiH'><style id='jvtiH'><dir id='jvtiH'><q id='jvtiH'></q></dir></style></legend>

              <small id='jvtiH'></small><noframes id='jvtiH'>

                1. <tfoot id='jvtiH'></tfoot>
                    <tbody id='jvtiH'></tbody>

                  本文介绍了无法腌制 &lt;type 'instancemethod'&gt;使用 python 的多处理 Pool.apply_async()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想运行这样的东西:

                  from multiprocessing  import Pool
                  import time
                  import random
                  
                  class Controler(object):
                      def __init__(self):
                          nProcess = 10
                          pages = 10
                          self.__result = []
                          self.manageWork(nProcess,pages)
                  
                  def BarcodeSearcher(x):
                      return x*x
                  
                  def resultCollector(self,result):
                      self.__result.append(result)
                  
                  def manageWork(self,nProcess,pages):
                      pool = Pool(processes=nProcess)
                      for pag in range(pages):
                          pool.apply_async(self.BarcodeSearcher, args = (pag, ), callback = self.resultCollector)
                  
                      print self.__result
                  
                  if __name__ == '__main__':
                      Controler()
                  

                  但代码导致错误:

                     Exception in thread Thread-1:
                  Traceback (most recent call last):
                    File "C:Python26lib	hreading.py", line 522, in __bootstrap_inner
                      self.run()
                    File "C:Python26lib	hreading.py", line 477, in run
                      self.__target(*self.__args, **self.__kwargs)
                    File "C:python26libmultiprocessingpool.py", line 225, in _handle_tasks
                      put(task)
                  PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed
                  

                  我看过帖子(post1 , post2) 来解决我的问题.我在第二篇文章中寻找类似 Mike McKerns 的解决方案,但没有使用悲情.

                  I've seen the posts (post1 , post2) to solve my problem. I'm looking for something like Mike McKerns solution in the second post but without using pathos.

                  推荐答案

                  这工作,使用 copy_reg,正如 Alex Martelli 在您提供的第一个链接中所建议的那样:

                  This works, using copy_reg, as suggested by Alex Martelli in the first link you provided:

                  import copy_reg
                  import types
                  import multiprocessing
                  
                  
                  def _pickle_method(m):
                      if m.im_self is None:
                          return getattr, (m.im_class, m.im_func.func_name)
                      else:
                          return getattr, (m.im_self, m.im_func.func_name)
                  
                  copy_reg.pickle(types.MethodType, _pickle_method)
                  
                  
                  class Controler(object):
                      def __init__(self):
                          nProcess = 10
                          pages = 10
                          self.__result = []
                          self.manageWork(nProcess, pages)
                  
                      def BarcodeSearcher(self, x):
                          return x*x
                  
                      def resultCollector(self, result):
                          self.__result.append(result)
                  
                      def manageWork(self, nProcess, pages):
                          pool = multiprocessing.Pool(processes=nProcess)
                          for pag in range(pages):
                              pool.apply_async(self.BarcodeSearcher, args=(pag,),
                                               callback=self.resultCollector)
                          pool.close()
                          pool.join()
                  
                          print(self.__result)
                  
                  if __name__ == '__main__':
                      Controler()
                  

                  这篇关于无法腌制 &lt;type 'instancemethod'&gt;使用 python 的多处理 Pool.apply_async()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:创建数据库连接并维护多个进程(多处理) 下一篇:我可以以某种方式与子进程共享一个异步队列吗

                  相关文章

                  最新文章

                    1. <i id='JhRAc'><tr id='JhRAc'><dt id='JhRAc'><q id='JhRAc'><span id='JhRAc'><b id='JhRAc'><form id='JhRAc'><ins id='JhRAc'></ins><ul id='JhRAc'></ul><sub id='JhRAc'></sub></form><legend id='JhRAc'></legend><bdo id='JhRAc'><pre id='JhRAc'><center id='JhRAc'></center></pre></bdo></b><th id='JhRAc'></th></span></q></dt></tr></i><div id='JhRAc'><tfoot id='JhRAc'></tfoot><dl id='JhRAc'><fieldset id='JhRAc'></fieldset></dl></div>
                    2. <legend id='JhRAc'><style id='JhRAc'><dir id='JhRAc'><q id='JhRAc'></q></dir></style></legend>
                      <tfoot id='JhRAc'></tfoot>

                      <small id='JhRAc'></small><noframes id='JhRAc'>

                      • <bdo id='JhRAc'></bdo><ul id='JhRAc'></ul>