久久久久久久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 機器上 IPython 控制臺中的多處理 - 如果 _

        multiprocessing in IPython console on Windows machine - if __name_ requirement(Windows 機器上 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 機器上 IPython 控制臺中的多處理 - 如果 __name_ 要求的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

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

                  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.

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

                  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.

                  例如,其中一個 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()
                  

                  觸發所有計算.但在 Windows 上,最終會出現 BrokenPipe 錯誤.

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

                  當我放

                  if __name__ == "__main__":
                       myFunction()
                  

                  在 py 文件的末尾并運行完整的文件

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

                  runfile(test.py)
                  

                  它有效.當然.但這使得向函數傳遞參數變得非常困難,因為我總是必須編輯 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.

                  推薦答案

                  所以,我解決了那個具體問題.

                  So, I solved that specific problem.

                  1. rand_string的定義放在一個單獨的文件中,叫做test2.

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

                  test2 作為模塊導入我的 test.py 腳本

                  Import test2 as module into my test.py script

                  將 test2 導入為 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)]
                  

                • 運行 test.py

                  調用myFunction()

                  要快樂:)

                  解決方案基于此多處理教程建議從另一個腳本導入目標函數.此解決方案繞過 if __name__ -wrapper 的安全自導入以訪問目標函數.

                  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.

                  這篇關于Windows 機器上 IPython 控制臺中的多處理 - 如果 __name_ 要求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

                  <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>

                            主站蜘蛛池模板: 91久久久久| 亚洲精品一区二三区不卡 | 亚洲国产91 | 免费av小说 | 亚洲精品观看 | 国产在线中文字幕 | 国产一级特黄aaa大片 | 欧美精品二区三区四区免费看视频 | 免费性网站 | 久艹在线 | 性视频网 | 在线播放毛片 | 99香蕉视频 | 亚洲成肉网 | 欧美美女视频 | 夜夜嗨av一区二区三区网页 | 日韩高清精品免费观看 | 久久免费视频网站 | av手机在线看 | 国产高清一区 | 天天久久综合 | 人人爽人人爽人人 | 婷婷久久久 | 亚洲欧美一区二区三区在线 | 欧美激情视频一区 | 在线不卡一区 | 日韩成人免费 | 欧美色偷偷 | 免费黄色片网站 | 97精品在线视频 | 日韩精品极品视频在线观看免费 | 在线观看国产小视频 | 国产精品第二页 | 亚洲精品三级 | 精品一区二区三区视频 | 黄色免费在线视频 | 成人一区二区三区 | 亚洲www. | www.狠狠操.com | 久久久精品在线观看 | 久久综合社区 |