使用 PyInstaller 创建的应用程序启动缓慢 [英] App created with PyInstaller has a slow startup

查看:52
本文介绍了使用 PyInstaller 创建的应用程序启动缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Python 编写并使用 PyInstaller编译"的应用程序.它还使用 PyQt 作为 GUI 框架.

在主窗口加载和显示之前运行此应用程序会有大约 10 秒的延迟.据我所知,这不是由于我的代码缓慢.相反,我怀疑这是由于 Python 运行时初始化造成的.

问题是这个应用程序是用自定义的启动器/任务栏应用程序启动的.用户将单击按钮启动应用程序,看不到任何事情发生,然后单击另一个应用程序的其他位置.当我的应用程序显示它的窗口时,由于 SetForegroundWindow 的规则,它无法进入前台.

我可以访问 PyInstaller win32 加载器的源代码、Python 代码,甚至启动器代码.

我的问题是:

  • 如何让这个应用程序启动得更快?

  • 如何衡量在进程生命周期的前几秒花费的时间?

  • 减少显示第一个窗口之前的时间的普遍接受的技术是什么?

我想避免添加启动画面有两个原因 - 一个,我认为它不会有帮助(开销是在 Python 代码运行之前),两个,我只是不喜欢启动画面:)

如果需要,我可能会编辑 PyInstaller 加载程序存根以创建一个窗口,但这是我不想采取的另一条路线.

解决方案

我使用 py2exe 和 cx_Freeze '编译'了一些 wxPython 应用程序,启动时间都不超过 4 秒.

  • 您确定这不是您的代码吗?也许是某个网络或某个 I/O 资源调用持有您的应用程序?
  • 您是否尝试过其他机器?即使是最快的硬件有时也会因软件配置、应用程序或操作系统错误而变慢,请尝试一下.
  • 尝试使用 timeit 模块计时.

我没用过pyQT,但是wxPython的启动速度还可以,而且第一次初始化后关闭再打开比第一次快.

I have an application written in Python and 'compiled' with PyInstaller. It also uses PyQt for the GUI framework.

Running this application has a delay of about 10 seconds before the main window loads and is shown. As far as I can tell, this is not due to slowness in my code. Instead, I suspect this is due to the Python runtime initializing.

The problem is that this application is started with a custom laucncher / taskbar application. The user will click the button to launch the app, see nothing appear to happen, and click elsewhere on another application. When my application shows it's window, it cannot come to the foreground due to the rules for SetForegroundWindow.

I have access to the source for the PyInstaller win32 loader, the Python code, and even the launcher code.

My questions are:

  • How can I make this application start faster?

  • How can I measure the time spend i the first few seconds of the process's lifetime?

  • What is the generally accepted technique for reducing time until the first window is shown?

I'd like to avoid adding a splash screen for two reasons - one, I expect it won't help (the overhead is before Python code runs) and two, I just don't like splash screens :)

If I need to, I could probably edit the PyInstaller loader stub to create a window, but that's another route i'd rather not take.

解决方案

I have 'compiled' a few wxPython apps using py2exe and cx_Freeze, None of them take more than 4 seconds to start.

  • Are you sure sure it's not your code ? maybe some network or some I/O resource call holding your app ?
  • Have you tried other machine than yours? Even the fastest hardware can be slow sometimes with the wrong software config, apps or OS, try it.
  • Try timing it with timeit module.

I never used pyQT, but with wxPython the startup speed is OK, and after the first initialize if I close and open again, it's faster than the first time.

这篇关于使用 PyInstaller 创建的应用程序启动缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆