cx2reader库和多处理的Python应用程序

2024-05-29 11:01:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将一个项目的早期版本移植到Windows并将其作为二进制文件分发。到目前为止,这个项目是在带有python3.3的archlinux中开发的,但是我想在Windows中将它打包为一个独立的二进制文件,以获得更多的测试用户。我已经确认,该代码在使用python3.3的Windows中运行正常。你知道吗

在尝试用cxfreeze编译它时,我遇到了一些问题。首先,我使用的主库(sc2reader)包含.csv文件形式的数据。在Windows中,这些文件位于\Python33\Lib\site packages\sc2reader中,但是cxfreeze在包含与sc2reader关联的大多数.py文件时忽略了包含它们。最初,生成的可执行文件会立即崩溃,并抱怨这些丢失的数据文件。手动添加后(我无法获取设置.py为了包含这些文件——cxfreeze不会抱怨任何语法错误,但也不会包含这些文件),我去掉了这些错误。你知道吗

我的设置.py看起来像这样:

import sys

from cx_Freeze import setup, Executable

build_exe_options = {"include_files": ['C:\Python33\Lib\site-packages\sc2reader\data\']}

setup(
    name = "vroMAD",
    version = "0.1.0",
    executables = [Executable("__main__.py", base = "base")]

在手动复制文件之后,我至少启动了二进制文件。它正确地绘制了窗口,但有些行为是不正确的。基本功能,如文件浏览和文件选择工作,但仅此而已。窗口中有一个按钮,它执行长任务并绘制进度条。因为这个长任务会阻止GUI更新,所以每当用户按下这个按钮时,就会产生第二个进程。但是,程序没有继续执行任务并更新进度条,而是创建了一个重复的窗口。事实上,任务管理器显示了一个额外的、相同的过程。新窗口的行为与旧窗口完全相同:它正确地处理基本事件,但当按下按钮时,它会生成另一个窗口。。。它们的行为方式是一样的。你知道吗

多处理不适用于cxfreeze吗?你知道吗


Tags: 文件项目用户pyimportwindowslibpackages
1条回答
网友
1楼 · 发布于 2024-05-29 11:01:38

你在给^{}打电话吗?你知道吗

Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exe, PyInstaller and cx_Freeze.)

One needs to call this function straight after the if __name__ == '__main__' line of the main module. For example:

from multiprocessing import Process, freeze_support

def f():
    print 'hello world!'

if __name__ == '__main__':
    freeze_support()
    Process(target=f).start()

If the freeze_support() line is omitted then trying to run the frozen executable will raise RuntimeError.

If the module is being run normally by the Python interpreter then freeze_support() has no effect.

而且,你是wrapping all the executing code in ^{},对吧?multiprocessing在Windows和Unix上的行为方式不同(因为缺少fork())。你知道吗

相关问题 更多 >

    热门问题