Pyinstaller打包python程序为exe时 程序多线程导致打开非常多窗口解决

装了个Pyinstaller打包exe

bash 复制代码
pip install Pyinstaller

打包命令

bash 复制代码
Pyinstaller -F main.py
Pyinstaller -F -w main.py #不带控制台
Pyinstaller -F -w -i 1.ico main.py #指定图标不带控制台

打包完的exe一运行开了一坨窗口,一眼多线程,我程序里的多线程如下

我把poolsize设置为1后问题确实消失,但是我不希望加密速度变慢

python 复制代码
def A生成秘钥并保存():
    pubkey, privkey = rsa.newkeys(4096, poolsize=16)  # 密钥长度128 256 512 1024 2048 3072 4096    poolsize=核心数

解决方法

Recipe Multiprocessing · pyinstaller/pyinstaller Wiki (github.com)

文档所示,windows和旧版本的pyinstaller打包都需要在main里加点神奇小料。

python 复制代码
if __name__ == '__main__':  

    multiprocessing.freeze_support() 
    #pyinstaller打包多线程需要,不然崩一堆窗口

调用的crypto库也是,windows底下有点问题要扯皮。

相关推荐
wjs20241 天前
Django Nginx+uWSGI 安装配置指南
开发语言
不知更鸟1 天前
Django 项目设置流程
后端·python·django
七夜zippoe1 天前
JVM类加载机制(Class Loading)详解:双亲委派模型与破坏实践
java·开发语言·jvm·类加载·双亲委派
曹牧1 天前
C#:无法从方法组转换为objec
开发语言·c#
自动化代码美学1 天前
【Python3.13】官网学习之控制流
开发语言·windows·python·学习
coderxiaohan1 天前
【C++】仿函数 + 模板进阶
开发语言·c++
IMPYLH1 天前
Lua 的 collectgarbage 函数
开发语言·笔记·junit·单元测试·lua
百锦再1 天前
第18章 高级特征
android·java·开发语言·后端·python·rust·django
Tony Bai1 天前
Go 在 Web3 的统治力:2025 年架构与生态综述
开发语言·后端·架构·golang·web3