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

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

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

      強制使用 if __name__==&quot;__main__&quot;在 Win

      Compulsory usage of if __name__==quot;__main__quot; in windows while using multiprocessing(強制使用 if __name__==quot;__main__quot;在 Windows 中同時使用多處理)
        <bdo id='DvBC6'></bdo><ul id='DvBC6'></ul>
      • <small id='DvBC6'></small><noframes id='DvBC6'>

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

              • 本文介紹了強制使用 if __name__==&quot;__main__&quot;在 Windows 中同時使用多處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                在 windows 上的 python 中使用多處理時,希望保護程序的入口點.文檔說確保新的 Python 解釋器可以安全地導入主模塊,而不會導致意外的副作用(例如啟動新進程)".誰能解釋一下這到底是什么意思?

                While using multiprocessing in python on windows, it is expected to protect the entry point of the program. The documentation says "Make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (such a starting a new process)". Can anyone explain what exactly does this mean ?

                推薦答案

                擴展一下你已經得到的好答案,如果你了解 Linux 系統做什么,它會有所幫助.它們使用 fork() 生成新進程,這有兩個 后果:

                Expanding a bit on the good answer you already got, it helps if you understand what Linux-y systems do. They spawn new processes using fork(), which has two good consequences:

                1. 主程序中存在的所有數據結構對子進程都是可見的.他們實際上是處理數據的副本.
                2. 子進程在主程序中緊跟 fork() 的指令處開始執行 - 因此任何已在模塊中執行的模塊級代碼都不會再次執行.
                1. All data structures existing in the main program are visible to the child processes. They actually work on copies of the data.
                2. The child processes start executing at the instruction immediately following the fork() in the main program - so any module-level code already executed in the module will not be executed again.

                fork() 在 Windows 中是不可能的,因此在 Windows 上,每個模塊都由每個子進程重新導入.所以:

                fork() isn't possible in Windows, so on Windows each module is imported anew by each child process. So:

                1. 在 Windows 上,no 存在于主程序中的數據結構對子進程是可見的;并且,
                2. 所有模塊級代碼在每個子進程中執行.
                1. On Windows, no data structures existing in the main program are visible to the child processes; and,
                2. All module-level code is executed in each child process.

                所以你需要考慮一下想要只在主程序中執行的代碼.最明顯的例子是,您希望創建子進程的代碼僅在主程序中運行——因此應該受到 __name__ == '__main__' 的保護.舉一個更微妙的例子,考慮構建一個巨大列表的代碼,您打算將其傳遞給工作進程以進行爬網.您可能也想保護它,因為在這種情況下,讓每個工作進程浪費 RAM 和時間來構建自己的巨大列表的無用副本是沒有意義的.

                So you need to think a bit about which code you want executed only in the main program. The most obvious example is that you want code that creates child processes to run only in the main program - so that should be protected by __name__ == '__main__'. For a subtler example, consider code that builds a gigantic list, which you intend to pass out to worker processes to crawl over. You probably want to protect that too, because there's no point in this case to make each worker process waste RAM and time building their own useless copies of the gigantic list.

                請注意,即使在 Linux 系統上適當地使用 __name__ == "__main__" 也是一個好主意,因為它使預期的工作分工更清晰.并行程序可能會令人困惑——每一點都有幫助 ;-)

                Note that it's a Good Idea to use __name__ == "__main__" appropriately even on Linux-y systems, because it makes the intended division of work clearer. Parallel programs can be confusing - every little bit helps ;-)

                這篇關于強制使用 if __name__==&quot;__main__&quot;在 Windows 中同時使用多處理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='xUbQc'></tfoot>
                  <i id='xUbQc'><tr id='xUbQc'><dt id='xUbQc'><q id='xUbQc'><span id='xUbQc'><b id='xUbQc'><form id='xUbQc'><ins id='xUbQc'></ins><ul id='xUbQc'></ul><sub id='xUbQc'></sub></form><legend id='xUbQc'></legend><bdo id='xUbQc'><pre id='xUbQc'><center id='xUbQc'></center></pre></bdo></b><th id='xUbQc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xUbQc'><tfoot id='xUbQc'></tfoot><dl id='xUbQc'><fieldset id='xUbQc'></fieldset></dl></div>
                  <legend id='xUbQc'><style id='xUbQc'><dir id='xUbQc'><q id='xUbQc'></q></dir></style></legend>

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

                          <tbody id='xUbQc'></tbody>
                          <bdo id='xUbQc'></bdo><ul id='xUbQc'></ul>
                          主站蜘蛛池模板: 免费观看成人鲁鲁鲁鲁鲁视频 | 午夜在线 | 一区二区三区四区日韩 | 黄色国产大片 | 精品视频在线观看 | 毛片网在线观看 | 91在线电影 | 草久久久 | 婷婷中文字幕 | 国产精品乱码一区二三区小蝌蚪 | 国产日韩欧美在线观看 | 天堂在线www| 特a毛片 | 日韩欧美在线一区二区 | 中文一区二区 | 欧美一级免费 | 亚洲视频在线看 | 天堂在线一区 | 欧美精品久久久久 | 国产精品亚洲精品 | 91av在线看| 色视频在线观看 | 国产综合视频 | 性欧美hd | 免费观看成人性生生活片 | 999久久久 | 91久久国产 | 在线观看涩涩视频 | 免费视频久久 | 亚洲 成人 av| 一区二区在线免费观看 | 欧美中文字幕一区二区三区亚洲 | 色婷婷一区二区三区四区 | 国产亚洲一区二区精品 | 国产激情一区二区三区 | 日韩精品在线播放 | 丝袜美腿一区二区三区 | 国产日韩欧美另类 | 四虎伊人 | 亚洲精品在线看 | 国产色视频网站 |