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

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

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

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

      1. <tfoot id='UOgEg'></tfoot>
          <bdo id='UOgEg'></bdo><ul id='UOgEg'></ul>

        Windows 機(jī)器上 IPython 控制臺中的多處理 - 如果 _

        multiprocessing in IPython console on Windows machine - if __name_ requirement(Windows 機(jī)器上 IPython 控制臺中的多處理 - 如果 __name_ 要求)
        • <bdo id='Jt8yG'></bdo><ul id='Jt8yG'></ul>

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

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

                  <tbody id='Jt8yG'></tbody>

                  <tfoot id='Jt8yG'></tfoot>
                  本文介紹了Windows 機(jī)器上 IPython 控制臺中的多處理 - 如果 __name_ 要求的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號..

                  我在 Windows 機(jī)器上使用 IPython 和 Spyder IDE.當(dāng) IDE 啟動時(shí),會加載一組 py 文件來定義一些使我的工作更輕松的函數(shù).一切正常.

                  I'm working with IPython and Spyder IDE on a Windows machine. When the IDE is starting, a set of py-files is loaded to define some functions that make my work a bit easier. Everything works as expected.

                  現(xiàn)在我想升級其中一個(gè)功能以使用多處理,但在 Windows 上,這需要 if __name__ == "__main__": 語句.因此,我似乎無法直接調(diào)用該函數(shù)并從 IPython 控制臺傳遞參數(shù).

                  Now I would like to upgrade one of these function to use multiprocessing, but on Windows this requires the if __name__ == "__main__": statement. So it seems that I cannot call the function directly and pass the arguments from the IPython console.

                  例如,其中一個(gè) py 文件(我們稱之為 test.py)可能類似于以下代碼.

                  For example one of the py-files (let's call it test.py) could look like the following code.

                  import multiprocessing as mp
                  import random
                  import string
                  
                  # define a example function
                  def rand_string(length, output):
                      """ Generates a random string of numbers, lower- and uppercase chars. """
                      rand_str = ''.join(random.choice(
                                  string.ascii_lowercase
                                  + string.ascii_uppercase
                                  + string.digits)
                             for i in range(length))
                      output.put(rand_str)
                  
                  
                  def myFunction():
                      # Define an output queue
                      output = mp.Queue()        
                  
                      # Setup a list of processes that we want to run
                      processes = [mp.Process(target=rand_string, args=(5, output)) for x in range(4)]
                  
                      # Run processes
                      for p in processes:
                          p.start()
                  
                      # Exit the completed processes
                      for p in processes:
                          p.join()
                  
                      # Get process results from the output queue
                      results = [output.get() for p in processes]
                  
                      print(results)
                  

                  在我的 IPython 控制臺中,我想使用該行

                  In my IPython console I would like to use the line

                  myFunction()
                  

                  觸發(fā)所有計(jì)算.但在 Windows 上,最終會出現(xiàn) BrokenPipe 錯(cuò)誤.

                  to trigger all the calculations. But on Windows a end up getting a BrokenPipe error.

                  當(dāng)我放

                  if __name__ == "__main__":
                       myFunction()
                  

                  在 py 文件的末尾并運(yùn)行完整的文件

                  at the end of the py-file and run the complete file by

                  runfile(test.py)
                  

                  它有效.當(dāng)然.但這使得向函數(shù)傳遞參數(shù)變得非常困難,因?yàn)槲铱偸潜仨毦庉?test.py 文件本身.

                  it works. Of course. But that makes it very hard to pass arguments to the function as I always have to edit the test.py-file itself.

                  推薦答案

                  所以,我解決了那個(gè)具體問題.

                  So, I solved that specific problem.

                  1. rand_string的定義放在一個(gè)單獨(dú)的文件中,叫做test2.

                  1. Put the defintion of rand_string in a separate file, called test2.

                  test2 作為模塊導(dǎo)入我的 test.py 腳本

                  Import test2 as module into my test.py script

                  將 test2 導(dǎo)入為 test2

                  修改以下行以訪問 test2 模塊

                  modify the following line to access the test2 module

                  processes = [mp.Process(target=test2.rand_string, args=(5, output)) for x in range(4)]
                  

                • 運(yùn)行 test.py

                  調(diào)用myFunction()

                  要快樂:)

                  解決方案基于此多處理教程建議從另一個(gè)腳本導(dǎo)入目標(biāo)函數(shù).此解決方案繞過 if __name__ -wrapper 的安全自導(dǎo)入以訪問目標(biāo)函數(shù).

                  The solution is based on this multiprocessing tutorial that suggests to import the target function from another script. This solution bypasses the safe self import by the if __name__ -wrapper to get access to the target function.

                  這篇關(guān)于Windows 機(jī)器上 IPython 控制臺中的多處理 - 如果 __name_ 要求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!
                • 相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                  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 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對象沒有屬性“f)

                  <small id='9sRMy'></small><noframes id='9sRMy'>

                        <tbody id='9sRMy'></tbody>

                        <legend id='9sRMy'><style id='9sRMy'><dir id='9sRMy'><q id='9sRMy'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 精品国产乱码久久久久久果冻传媒 | 在线观看国产 | 国产精产国品一二三产区视频 | 在线看片国产精品 | 天天干天天爱天天操 | 99精品久久久国产一区二区三 | 91社影院在线观看 | 美女福利视频 | 婷婷国产一区 | 久久久久国产一级毛片高清网站 | 久久久久久综合 | 91免费观看 | 日本三级网 | 国产一区二区三区久久久久久久久 | 国产欧美一区二区在线观看 | 亚洲欧美日韩高清 | 天天艹逼网 | 日本不卡一区二区三区 | 久久精品小视频 | 在线欧美视频 | 国产精品久久久久久久久久久久冷 | 国产精品福利网站 | 最近中文字幕免费 | 亚洲精品在线视频 | 日韩精品免费视频 | 亚洲精品久久 | 色资源在线 | a网站在线观看 | 亚洲国产视频一区二区 | 久久久亚洲综合 | 久久影音先锋 | 亚洲精品久久久一区二区三区 | 成人精品在线观看 | 亚洲国产精品日韩av不卡在线 | 天天精品综合 | 欧美4p | 91免费观看在线 | 亚洲字幕在线观看 | 精品国产精品三级精品av网址 | 欧美日韩不卡在线 | 91在线精品一区二区 |