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

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

      <tfoot id='eL8HG'></tfoot>

        PyInstaller 構建的 Windows EXE 因多處理而失敗

        PyInstaller-built Windows EXE fails with multiprocessing(PyInstaller 構建的 Windows EXE 因多處理而失敗)

            <tbody id='gXrEN'></tbody>

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

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

                • <legend id='gXrEN'><style id='gXrEN'><dir id='gXrEN'><q id='gXrEN'></q></dir></style></legend>
                  <tfoot id='gXrEN'></tfoot>
                  本文介紹了PyInstaller 構建的 Windows EXE 因多處理而失敗的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在我的項目中,我使用 Python 的 multiprocessing 庫在 __main__ 中創建多個進程.該項目正在使用 PyInstaller 2.1.1 打包到單個 Windows EXE 中.

                  In my project I'm using Python's multiprocessing library to create multiple processes in __main__. The project is being packaged into a single Windows EXE using PyInstaller 2.1.1.

                  我像這樣創建新流程:

                  from multiprocessing import Process
                  from Queue import Empty
                  
                  def _start():
                      while True:
                          try:
                              command = queue.get_nowait()
                          # ... and some more code to actually interpret commands
                          except Empty:
                              time.sleep(0.015)
                  
                  def start():
                      process = Process(target=_start, args=args)
                      process.start()
                      return process
                  

                  在 __main__ 中:

                  And in __main__:

                  if __name__ == '__main__':
                      freeze_support()
                  
                      start()
                  

                  不幸的是,在將應用程序打包成 EXE 并啟動它時,我在這一行得到 WindowsError 5 或 6(似乎是隨機的):

                  Unfortunately, when packaging the application into an EXE and launching it, I get WindowsError 5 or 6 (seems random) at this line:

                  command = queue.get_nowait()
                  

                  PyInstaller 主頁上的一個配方聲稱,在將應用程序打包為單個文件時,我必須修改我的代碼以在 Windows 中啟用多處理.

                  A recipe at PyInstaller's homepage claims that I have to modify my code to enable multiprocessing in Windows when packaging the application as a single file.

                  我在這里復制代碼:

                  import multiprocessing.forking
                  import os
                  import sys
                  
                  
                  class _Popen(multiprocessing.forking.Popen):
                      def __init__(self, *args, **kw):
                          if hasattr(sys, 'frozen'):
                              # We have to set original _MEIPASS2 value from sys._MEIPASS
                              # to get --onefile mode working.
                              # Last character is stripped in C-loader. We have to add
                              # '/' or '\' at the end.
                              os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
                          try:
                              super(_Popen, self).__init__(*args, **kw)
                          finally:
                              if hasattr(sys, 'frozen'):
                                  # On some platforms (e.g. AIX) 'os.unsetenv()' is not
                                  # available. In those cases we cannot delete the variable
                                  # but only set it to the empty string. The bootloader
                                  # can handle this case.
                                  if hasattr(os, 'unsetenv'):
                                      os.unsetenv('_MEIPASS2')
                                  else:
                                      os.putenv('_MEIPASS2', '')
                  
                  
                  class Process(multiprocessing.Process):
                      _Popen = _Popen
                  
                  
                  class SendeventProcess(Process):
                      def __init__(self, resultQueue):
                          self.resultQueue = resultQueue
                  
                          multiprocessing.Process.__init__(self)
                          self.start()
                  
                      def run(self):
                          print 'SendeventProcess'
                          self.resultQueue.put((1, 2))
                          print 'SendeventProcess'
                  
                  
                  if __name__ == '__main__':
                      # On Windows calling this function is necessary.
                      if sys.platform.startswith('win'):
                          multiprocessing.freeze_support()
                      print 'main'
                      resultQueue = multiprocessing.Queue()
                      SendeventProcess(resultQueue)
                      print 'main'
                  

                  我對這個解決方案"的失望在于,第一,完全不清楚它到底在修補什么,第二,它的編寫方式如此復雜,以至于無法推斷出哪些部分是解決方案,哪些部分是解決方案.只是一個插圖.

                  My frustration with this "solution" is that, one, it's absolutely unclear what exactly it is patching, and, two, that it's written in such a convoluted way that it becomes impossible to infer which parts are the solution, and which are just an illustration.

                  任何人都可以就這個問題分享一些觀點,并提供見解在一個項目中究竟需要更改哪些內容,以便在 PyInstaller 構建的單文件 Windows 可執行文件中啟用多處理?

                  Can anyone share some light on this issue, and provide insight what exactly needs to be changed in a project that enables multiprocessing in PyInstaller-built single-file Windows executables?

                  推薦答案

                  找到這個PyInstaller后回答我自己的問題票:

                  顯然我們所要做的就是提供一個如下所示的Process(和_Popen)類,并使用它來代替multiprocessing.Process.我已更正并簡化了該類,使其僅適用于 Windows,*ix 系統可能需要不同的代碼.

                  Apparently all we have to do is provide a Process (and _Popen) class as shown below, and use it instead of multiprocessing.Process. I've corrected and simplified the class to work on Windows only, *ix systems might need different code.

                  為了完整起見,以下是上述問題的改編樣本:

                  For the sake of completeness, here's the adapted sample from the above question:

                  import multiprocessing
                  from Queue import Empty
                  
                  class _Popen(multiprocessing.forking.Popen):
                      def __init__(self, *args, **kw):
                          if hasattr(sys, 'frozen'):
                              os.putenv('_MEIPASS2', sys._MEIPASS)
                          try:
                              super(_Popen, self).__init__(*args, **kw)
                          finally:
                              if hasattr(sys, 'frozen'):
                                  os.unsetenv('_MEIPASS2')
                  
                  
                  class Process(multiprocessing.Process):
                      _Popen = _Popen
                  
                  
                  def _start():
                      while True:
                          try:
                              command = queue.get_nowait()
                          # ... and some more code to actually interpret commands
                          except Empty:
                              time.sleep(0.015)
                  
                  def start():
                      process = Process(target=_start, args=args)
                      process.start()
                      return process
                  

                  這篇關于PyInstaller 構建的 Windows EXE 因多處理而失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='SzxQ3'></tfoot>

                    <bdo id='SzxQ3'></bdo><ul id='SzxQ3'></ul>

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

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

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

                            主站蜘蛛池模板: 男人的天堂在线视频 | 国产乱码精品1区2区3区 | 日韩电影中文字幕 | 91最新入口| 九九热在线观看视频 | 精品粉嫩aⅴ一区二区三区四区 | 国产在线观看一区 | 成人免费看黄网站在线观看 | 91免费电影| 做a视频在线观看 | 91麻豆精品国产91久久久资源速度 | 国产精品久久国产精品 | 久久久精品视频一区二区三区 | 欧美一级片免费看 | www日本高清 | 亚洲aⅴ| 久久免费精品 | 一级毛片视频 | 午夜视频在线免费观看 | 亚洲欧美国产精品久久 | 日韩字幕 | 天天操夜夜看 | 国产精品3区 | 亚洲精品福利在线 | 久久r精品 | 亚洲精品视频免费观看 | 日韩中文在线观看 | 午夜免费福利片 | 中文字幕一区二区三区乱码图片 | 日韩视频一区在线观看 | 最近中文字幕在线视频1 | 伊人春色成人网 | 久久久久国产一区二区三区四区 | 成人av一区| 国产激情视频网站 | 91视视频在线观看入口直接观看 | 毛片免费观看视频 | 99精品久久久 | 国产精久久久久久 | 国产成人精品一区二区三区在线 | 亚洲欧美一区二区三区视频 |