cx-freeze,runpy和multiprocessing - 多个失败路径

时间:2023-01-31 23:00:54

This is a bit of a complex one, and may take some of your time.

这有点复杂,可能需要一些时间。

The basic problem is, that on linux (Ubuntu in my test case) a cx-freeze'd version of my program (Omnitool) is not able to create subprocesses. It works on Windows 7, however. Or when running directly from source code. Unfortunately it's not as simple as forgetting freeze_support.

基本问题是,在Linux上(在我的测试用例中是Ubuntu)我的程序(Omnitool)的cx-freeze'd版本无法创建子进程。但它适用于Windows 7。或者直接从源代码运行时。不幸的是,它并不像忘记freeze_support那么简单。

The Problem

问题

Default behaviour of starting a subprocess, is that the X Server crashes. Specifically like this:

启动子进程的默认行为是X服务器崩溃。具体如下:

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 23 requests (23 known processed) with 0 events remaining.
[xcb]Unknown sequence number while processing queue 
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 
[xcb] Aborting, sorry about that. 
Omnitool: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. 
Aborted (core dumped)

There is no python traceback. I tried to manually call XInitThreads with ctypes, it returns 0 for successfully set, but crashes regardless. Shorty before the crash, the pygame UI bugs out, so I expect that something there faults.

没有python回溯。我试图用ctypes手动调用XInitThreads,它成功设置返回0,但无论如何崩溃。在崩溃之前Shorty,pygame UI漏掉了,所以我希望有一些错误。

Now, setting multiprocessing.set_start_method() changes problems around: "forkserver" gives me this lovely traceback, that tells me nothing:

现在,设置multiprocessing.set_start_method()可以改变周围的问题:“forkserver”给了我这个可爱的回溯,它什么也没告诉我:

Pastebin Example

Pastebin例子

Setting it to spawn, instead, just makes it not do anything. The process starts, and goes through __main__, as I can prove with prints, but never enters the target function for the subprocess.

相反,将它设置为spawn只是让它不做任何事情。该过程开始,并通过__main__,因为我可以用打印证明,但永远不会进入子进程的目标函数。

Trying yourself

试着自己

Make sure you have Ubuntu or comparable Linux with python 3.4. Then to get all dependencies:

确保你有使用python 3.4的Ubuntu或类似的Linux。然后获取所有依赖项:

Download omnitool as zip or clone from git: https://github.com/Berserker66/omnitool requirements.txt in the following code is from Omnitool.

从git下载omnitool作为zip或克隆:https://github.com/Berserker66/omnitool requirements.txt在下面的代码中来自Omnitool。

sudo apt-get update -qq
sudo apt-get install --fix-missing mercurial subversion python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev python3-pip
pip3 install -r requirements.txt
pip3 install cx_Freeze

To freeze, run omnisetup.py with the buildargument.

要冻结,请使用buildargument运行omnisetup.py。

I've also tried freezing with pyinstallers python 3 fork, which fails very similar. The spec file isn't git tracked though.

我也尝试使用pyinstallers python 3 fork进行冻结,这非常类似。但是spec文件不是git跟踪的。

3 个解决方案

#1


1  

I used cx_freeze for a project at work. I'm not sure if this is your problem... but I was using the Anaconda distribution, and cx_freeze was not properly gathering the .dll's that I needed for my project.

我在工作中使用cx_freeze作为项目。我不确定这是不是你的问题...但是我使用的是Anaconda发行版,并且cx_freeze没有正确地收集我项目所需的.dll。

The solution was to:

解决方案是:

  1. Install a plane version of Python
  2. 安装Python的平面版本
  3. make an environment with the packages that I needed for that project
  4. 使用我为该项目所需的包创建一个环境
  5. Run cx_freeze.
  6. 运行cx_freeze。

Magically, all of the problems went away and everything compiled like it was supposed too.

奇迹般地,所有的问题都消失了,所有编译的东西也都是如此。

#2


0  

I know that probably this is not what you want to hear, but the reality is that you will never be able to succeed with this approach and here is why:

我知道这可能不是你想听到的,但现实是你永远无法用这种方法取得成功,这就是为什么:

  • Linux does not have portably Python package binaries, meaning that a compiled numpy on one distro will probably not work on another. It can even happen with the same distribution and version, just because one system library received an update.
  • Linux没有可移植的Python包二进制文件,这意味着一个发行版上的编译numpy可能不适用于另一个发行版。它甚至可以在相同的发行版和版本中发生,只是因为一个系统库收到了更新。
  • manylinux1 is supposed to solve this but is really hard to build packages for it and only few started using it.
  • manylinux1应该解决这个问题但很难为它构建软件包,只有少数人开始使用它。
  • cx-freeze project had latest release in December 2014, which on Python timescale puts it as an abandoned project.
  • cx-freeze项目于2014年12月发布,在Python时间表上将其作为一个废弃的项目。

#3


0  

Well the problem you are facing may be due to the lack of dependencies. cx_Freeze have some dependencies. In order to distribute your work in python many lightweight packages are avalible. You can use:-

那么你面临的问题可能是由于缺乏依赖性。 cx_Freeze有一些依赖。为了在python中分发你的工作,许多轻量级包都是可用的。您可以使用:-

  1. Pyinstaller: it can be installed by

    Pyinstaller:它可以安装

    pip install pyinstaller pyinstaller is really good for making executables with less size

    pip install pyinstaller pyinstaller非常适合制作尺寸较小的可执行文件

  2. Py2exe

    Py2exe

#1


1  

I used cx_freeze for a project at work. I'm not sure if this is your problem... but I was using the Anaconda distribution, and cx_freeze was not properly gathering the .dll's that I needed for my project.

我在工作中使用cx_freeze作为项目。我不确定这是不是你的问题...但是我使用的是Anaconda发行版,并且cx_freeze没有正确地收集我项目所需的.dll。

The solution was to:

解决方案是:

  1. Install a plane version of Python
  2. 安装Python的平面版本
  3. make an environment with the packages that I needed for that project
  4. 使用我为该项目所需的包创建一个环境
  5. Run cx_freeze.
  6. 运行cx_freeze。

Magically, all of the problems went away and everything compiled like it was supposed too.

奇迹般地,所有的问题都消失了,所有编译的东西也都是如此。

#2


0  

I know that probably this is not what you want to hear, but the reality is that you will never be able to succeed with this approach and here is why:

我知道这可能不是你想听到的,但现实是你永远无法用这种方法取得成功,这就是为什么:

  • Linux does not have portably Python package binaries, meaning that a compiled numpy on one distro will probably not work on another. It can even happen with the same distribution and version, just because one system library received an update.
  • Linux没有可移植的Python包二进制文件,这意味着一个发行版上的编译numpy可能不适用于另一个发行版。它甚至可以在相同的发行版和版本中发生,只是因为一个系统库收到了更新。
  • manylinux1 is supposed to solve this but is really hard to build packages for it and only few started using it.
  • manylinux1应该解决这个问题但很难为它构建软件包,只有少数人开始使用它。
  • cx-freeze project had latest release in December 2014, which on Python timescale puts it as an abandoned project.
  • cx-freeze项目于2014年12月发布,在Python时间表上将其作为一个废弃的项目。

#3


0  

Well the problem you are facing may be due to the lack of dependencies. cx_Freeze have some dependencies. In order to distribute your work in python many lightweight packages are avalible. You can use:-

那么你面临的问题可能是由于缺乏依赖性。 cx_Freeze有一些依赖。为了在python中分发你的工作,许多轻量级包都是可用的。您可以使用:-

  1. Pyinstaller: it can be installed by

    Pyinstaller:它可以安装

    pip install pyinstaller pyinstaller is really good for making executables with less size

    pip install pyinstaller pyinstaller非常适合制作尺寸较小的可执行文件

  2. Py2exe

    Py2exe