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

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

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

        為什么在'__main__'中導入模塊不允許multipr

        Why does importing module in #39;__main__#39; not allow multiprocessig to use module?(為什么在__main__中導入模塊不允許multiprocessig使用模塊?)

          <tbody id='wnFIe'></tbody>

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

            • <small id='wnFIe'></small><noframes id='wnFIe'>

                  <bdo id='wnFIe'></bdo><ul id='wnFIe'></ul>
                  本文介紹了為什么在'__main__'中導入模塊不允許multiprocessig使用模塊?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我已經通過將導入移到頂部聲明解決了我的問題,但這讓我想知道:為什么我不能在函數中使用在 '__main__' 中導入的模塊multiprocessing 的目標?

                  I've already solved my problem by moving the import to the top declarations, but it left me wondering: Why cant I use a module that was imported in '__main__' in functions that are the targets of multiprocessing?

                  例如:

                  import os
                  import multiprocessing as mp
                  
                  def run(in_file, out_dir, out_q):
                      arcpy.RaterToPolygon_conversion(in_file, out_dir, "NO_SIMPIFY", "Value")
                      status = str("Done with "+os.path.basename(in_file))
                      out_q.put(status, block=False)
                  
                  if __name__ == '__main__':
                      raw_input("Program may hang, press Enter to import ArcPy...")
                      import arcpy
                  
                      q = mp.Queue()
                      _file = path/to/file
                      _dir = path/to/dir
                      # There are actually lots of files in a loop to build
                      # processes but I just do one for context here
                      p = mp.Process(target=run, args=(_file, _dir, q))
                      p.start()
                  
                  # I do stuff with Queue below to status user
                  

                  當您在 IDLE 中運行它時,它根本不會出錯...只是繼續進行 Queue 檢查(這很好,所以不是問題).問題是,當您在 CMD 終端(操作系統或 Python)中運行它時,會產生 arcpy 未定義的錯誤!

                  When you run this in IDLE it doesn't error at all...just keeps doing a Queue check (which is good so not the problem). The problem is that when you run this in the CMD terminal (either OS or Python) it produces the error that arcpy is not defined!

                  只是一個奇怪的話題.

                  推薦答案

                  類unix系統和windows的情況不同.在 unixy 系統上,multiprocessing 使用 fork 創建共享父內存空間的寫時復制視圖的子進程.子進程會看到來自父進程的導入,包括父進程在 if __name__ == "__main__": 下導入的任何內容.

                  The situation is different in unix-like systems and Windows. On the unixy systems, multiprocessing uses fork to create child processes that share a copy-on-write view of the parent memory space. The child sees the imports from the parent, including anything the parent imported under if __name__ == "__main__":.

                  在 windows 上,沒有 fork,必須執行一個新進程.但是簡單地重新運行父進程是行不通的——它會再次運行整個程序.相反,multiprocessing 運行自己的 python 程序,該程序導入父主腳本,然后腌制/取消腌制父對象空間的視圖,希望這對于子進程來說足夠了.

                  On windows, there is no fork, a new process has to be executed. But simply rerunning the parent process doesn't work - it would run the whole program again. Instead, multiprocessing runs its own python program that imports the parent main script and then pickles/unpickles a view of the parent object space that is, hopefully, sufficient for the child process.

                  該程序是子進程的 __main__ 并且父腳本的 __main__ 不運行.主腳本就像任何其他模塊一樣被導入.原因很簡單:運行父 __main__ 只會再次運行完整的父程序,這是 mp 必須避免的.

                  That program is the __main__ for the child process and the __main__ of the parent script doesn't run. The main script was just imported like any other module. The reason is simple: running the parent __main__ would just run the full parent program again, which mp must avoid.

                  這是一個測試來顯示發生了什么.一個名為 testmp.py 的主模塊和一個由第一個模塊導入的第二個模塊 test2.py.

                  Here is a test to show what is going on. A main module called testmp.py and a second module test2.py that is imported by the first.

                  testmp.py

                  import os
                  import multiprocessing as mp
                  
                  print("importing test2")
                  import test2
                  
                  def worker():
                      print('worker pid: {}, module name: {}, file name: {}'.format(os.getpid(), 
                          __name__, __file__))
                  
                  if __name__ == "__main__":
                      print('main pid: {}, module name: {}, file name: {}'.format(os.getpid(), 
                          __name__, __file__))
                      print("running process")
                      proc = mp.Process(target=worker)
                      proc.start()
                      proc.join()
                  

                  test2.py

                  import os
                  
                  print('test2 pid: {}, module name: {}, file name: {}'.format(os.getpid(),
                          __name__, __file__))
                  

                  在 Linux 上運行時,test2 被導入一次,worker 運行在主模塊中.

                  When run on Linux, test2 is imported once and the worker runs in the main module.

                  importing test2
                  test2 pid: 17840, module name: test2, file name: /media/td/USB20FD/tmp/test2.py
                  main pid: 17840, module name: __main__, file name: testmp.py
                  running process
                  worker pid: 17841, module name: __main__, file name: testmp.py
                  

                  在 windows 下,請注意importing test2"打印了兩次 - testmp.py 運行了兩次.但是main pid"只打印了一次——它的 __main__ 沒有運行.那是因為 multiprocessing 在導入期間將模塊名稱更改為 __mp_main__.

                  Under windows, notice that "importing test2" is printed twice - testmp.py was run two times. But "main pid" was only printed once - its __main__ wasn't run. That's because multiprocessing changed the module name to __mp_main__ during import.

                  E:	mp>py testmp.py
                  importing test2
                  test2 pid: 7536, module name: test2, file name: E:	mp	est2.py
                  main pid: 7536, module name: __main__, file name: testmp.py
                  running process
                  importing test2
                  test2 pid: 7544, module name: test2, file name: E:	mp	est2.py
                  worker pid: 7544, module name: __mp_main__, file name: E:	mp	estmp.py
                  

                  這篇關于為什么在'__main__'中導入模塊不允許multiprocessig使用模塊?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='fQ4x8'></tfoot>
                  • <bdo id='fQ4x8'></bdo><ul id='fQ4x8'></ul>

                  • <legend id='fQ4x8'><style id='fQ4x8'><dir id='fQ4x8'><q id='fQ4x8'></q></dir></style></legend>

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

                          <tbody id='fQ4x8'></tbody>

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

                          • 主站蜘蛛池模板: av免费在线观看网站 | 亚洲日本国产 | 国产精品日韩精品 | 免费黄色小网站 | 一色桃子av | 欧美黄色免费网站 | 日本福利在线 | 成人深夜 | 一区二区三区视频在线播放 | 亚洲动漫精品 | 97人人插| 69视频在线播放 | 免费网站www| 国产日韩在线视频 | 日皮视频免费看 | 国产欧美日韩一区 | 天天爽夜夜爽夜夜爽精品视频 | 99这里有精品 | 欧美人与性动交α欧美精品 | 毛片一级片 | 欧美成人综合 | 日韩中文字幕一区二区三区 | 日本国产视频 | 午夜精品视频 | 天天干少妇 | 91综合在线 | 精品国产91乱码一区二区三区 | 国产精品伦子伦免费视频 | 成人一级视频 | 久久国产精品一区二区三区 | 成人福利在线观看 | 18色av| 欧美一区二区三区视频 | 黄色小视频在线免费观看 | 秋霞一区二区 | 国产二区精品 | 亚洲观看黄色网 | 日韩二三区 | av资源在线 | 成人激情在线观看 | www精品|