久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

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

        Python 2.7:如何彌補缺少的 pool.starmap?

        Python 2.7: How to compensate for missing pool.starmap?(Python 2.7:如何彌補缺少的 pool.starmap?)

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

          <tfoot id='WnYX4'></tfoot>

              <i id='WnYX4'><tr id='WnYX4'><dt id='WnYX4'><q id='WnYX4'><span id='WnYX4'><b id='WnYX4'><form id='WnYX4'><ins id='WnYX4'></ins><ul id='WnYX4'></ul><sub id='WnYX4'></sub></form><legend id='WnYX4'></legend><bdo id='WnYX4'><pre id='WnYX4'><center id='WnYX4'></center></pre></bdo></b><th id='WnYX4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WnYX4'><tfoot id='WnYX4'></tfoot><dl id='WnYX4'><fieldset id='WnYX4'></fieldset></dl></div>
              • <bdo id='WnYX4'></bdo><ul id='WnYX4'></ul>
                <legend id='WnYX4'><style id='WnYX4'><dir id='WnYX4'><q id='WnYX4'></q></dir></style></legend>
                    <tbody id='WnYX4'></tbody>
                • 本文介紹了Python 2.7:如何彌補缺少的 pool.starmap?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我已經定義了這個函數

                  def writeonfiles(a,seed):
                      random.seed(seed)
                  
                      f = open(a, "w+")
                      for i in range(0,10):
                          j = random.randint(0,10)
                          #print j
                          f.write(j)
                      f.close()
                  

                  其中 a 是包含文件路徑的字符串,seed 是整數種子.我想以這樣一種方式并行化一個簡單的程序,即每個內核采用我提供的可用路徑之一,為其隨機生成器播種并在該文件上寫入一些隨機數,例如,如果我通過向量

                  Where a is a string containing the path of the file and seed is an integer seed. I want to parallelize a simple program in such a way that each core takes one of the available paths that I give in, seeds its random generator and write some random numbers on that files, so, for example, if I pass the vector

                  vector = [Test/file1.txt, Test/file2.txt] 
                  

                  和種子

                  seeds = (123412, 989898), 
                  

                  它為第一個可用的核心提供功能

                  it gives to the first available core the function

                  writeonfiles(Test/file1.txt, 123412) 
                  

                  對于第二個具有不同參數的相同函數:

                  and to the second one the same function with different arguments:

                  writeonfiles(Test/file2.txt, 989898)
                  

                  我在 Stackoverflow 上查看了很多類似的問題,但我無法做出任何解決方案.我嘗試的是:

                  I have looked through a lot of similar questions here on Stackoverflow, but I cannot make any solution work. What I tried is:

                  def writeonfiles_unpack(args):
                      return writeonfiles(*args)
                  if __name__ == "__main__":
                       folder = ["Test/%d.csv" %i for i in range(0,4)]
                       seed = [234124, 663123, 12345 ,123833]
                       p = multiprocessing.Pool()
                       p.map(writeonfiles, (folder,seed))
                  

                  并給我 TypeError: writeonfiles() 正好需要 2 個參數(1 個給定).

                  and gives me TypeError: writeonfiles() takes exactly 2 arguments (1 given).

                  我也試過了

                  if __name__ == "__main__":
                      folder = ["Test/%d.csv" %i for i in range(0,4)]
                      seed = [234124, 663123, 12345 ,123833]
                      p = multiprocessing.Process(target=writeonfiles, args= [folder,seed])
                      p.start()
                  

                  但它給了我
                  種子文件/usr/lib/python2.7/random.py",第 120 行超級(隨機,自我).seed(一)TypeError: unhashable type: 'list'

                  But it gives me
                  File "/usr/lib/python2.7/random.py", line 120, in seed super(Random, self).seed(a) TypeError: unhashable type: 'list'

                  最后,我嘗試了上下文管理器

                  Finally, I tried the contextmanager

                   @contextmanager
                   def poolcontext(*args, **kwargs):
                       pool = multiprocessing.Pool(*args, **kwargs)
                       yield pool
                       pool.terminate()
                  
                  if __name__ == "__main__":
                      folder = ["Test/%d" %i for i in range(0,4)]
                      seed = [234124, 663123, 12345 ,123833]
                      a = zip(folder, seed)
                      with poolcontext(processes = 3) as pool:
                      results = pool.map(writeonfiles_unpack,a )
                  

                  它會導致文件/usr/lib/python2.7/multiprocessing/pool.py",第 572 行,在 get提高self._value

                  and it results in File "/usr/lib/python2.7/multiprocessing/pool.py", line 572, in get raise self._value

                  TypeError: 'module' 對象不可調用

                  TypeError: 'module' object is not callable

                  推薦答案

                  Python 2.7 缺少 Python 3.3+ 中的 starmap 池方法.您可以通過使用包裝器來裝飾您的目標函數來克服這個問題,該包裝器將參數元組解包并調用目標函數:

                  Python 2.7 lacks the starmap pool-method from Python 3.3+ . You can overcome this by decorating your target function with a wrapper, which unpacks the argument-tuple and calls the target function:

                  import os
                  from multiprocessing import Pool
                  import random
                  from functools import wraps
                  
                  
                  def unpack(func):
                      @wraps(func)
                      def wrapper(arg_tuple):
                          return func(*arg_tuple)
                      return wrapper
                  
                  @unpack
                  def write_on_files(a, seed):
                      random.seed(seed)
                      print("%d opening file %s" % (os.getpid(), a))  # simulate
                      for _ in range(10):
                          j = random.randint(0, 10)
                         print("%d writing %d to file %s" % (os.getpid(), j, a))  # simulate
                  
                  
                  if __name__ == '__main__':
                  
                      folder = ["Test/%d.csv" % i for i in range(0, 4)]
                      seed = [234124, 663123, 12345, 123833]
                  
                      arguments = zip(folder, seed)
                  
                      pool = Pool(4)
                      pool.map(write_on_files, iterable=arguments)
                      pool.close()
                      pool.join()
                  

                  這篇關于Python 2.7:如何彌補缺少的 pool.starmap?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

                  <tfoot id='6ROsO'></tfoot>

                  • <bdo id='6ROsO'></bdo><ul id='6ROsO'></ul>
                      <tbody id='6ROsO'></tbody>

                      <i id='6ROsO'><tr id='6ROsO'><dt id='6ROsO'><q id='6ROsO'><span id='6ROsO'><b id='6ROsO'><form id='6ROsO'><ins id='6ROsO'></ins><ul id='6ROsO'></ul><sub id='6ROsO'></sub></form><legend id='6ROsO'></legend><bdo id='6ROsO'><pre id='6ROsO'><center id='6ROsO'></center></pre></bdo></b><th id='6ROsO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6ROsO'><tfoot id='6ROsO'></tfoot><dl id='6ROsO'><fieldset id='6ROsO'></fieldset></dl></div>

                        <small id='6ROsO'></small><noframes id='6ROsO'>

                        • <legend id='6ROsO'><style id='6ROsO'><dir id='6ROsO'><q id='6ROsO'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 国产精品久久av | 欧美精品一区二区三区在线播放 | 亚洲精品白浆高清久久久久久 | 亚洲视频在线一区 | 欧美一级在线 | 色www精品视频在线观看 | 99精品免费 | 观看av| 天天天久久久 | 精品一区二区三区在线观看国产 | 日本久久精品 | 日韩中文字幕网 | 欧美精品一区二区三区在线播放 | 欧美男人亚洲天堂 | 无码日韩精品一区二区免费 | 一区二区三区四区在线 | 欧美精品一区二区三区在线播放 | 久久精品国产v日韩v亚洲 | 久久99精品久久久久久 | 久久91精品久久久久久9鸭 | 日韩视频一区二区 | 久久综合av | 久久久久久久久久久高潮一区二区 | 一级欧美视频 | 免费国产一区二区 | 国产在线97| 91影院在线观看 | 91免费小视频| 精品一区二区三区在线观看国产 | 国产精品视频久久久 | 国产精品自拍视频网站 | 亚洲精品一级 | 成人小视频在线免费观看 | 日韩欧美亚洲 | 国产欧美日韩综合精品一 | 伊人网站在线观看 | 三级免费毛片 | 久久99国产精一区二区三区 | 婷婷去俺也去 | 一本一道久久a久久精品综合蜜臀 | 日韩欧美国产精品一区二区三区 |