Pyinstaller多進(jìn)程代碼打包exe出現(xiàn)多個(gè)進(jìn)程解決方案

參考:
https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
http://blog.csdn.net/xiong_big/article/details/54614231

在工程下新建py文件 frozen.py

import os  
import sys  
import multiprocessing  
  
# Module multiprocessing is organized differently in Python 3.4+  
try:  
    # Python 3.4+  
    if sys.platform.startswith('win'):  
        import multiprocessing.popen_spawn_win32 as forking  
    else:  
        import multiprocessing.popen_fork as forking  
except ImportError:  
    import multiprocessing.forking as forking  
  
if sys.platform.startswith('win'):  
    # First define a modified version of Popen.  
    class _Popen(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.  
                os.putenv('_MEIPASS2', sys._MEIPASS)  
            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', '')  
  
    # Second override 'Popen' class with our modified version.  
    forking.Popen = _Popen   ?

在多進(jìn)程代碼py文件中加入

import frozen 

最后直接在 if name=='main': 的下面一行加入:

multiprocessing.freeze_support()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容