Python 3.2 Multiprocessing.Process 未运行目标函数 [英] Python 3.2 Multiprocessing.Process not running target function

查看:79
本文介绍了Python 3.2 Multiprocessing.Process 未运行目标函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我不知道是什么问题.嵌入的代码(来自 3.2 文档的最简单的示例代码,只是为了尝试调试)将不会运行目标函数.Process完成,程序导入运行无错误,Python 3.2安装正确,目录添加到Path环境变量中.我正在使用 f5 从 IDLE 运行程序,并且所有其他代码都可以完美运行,但是目标函数f"(在这种情况下)中的代码根本无法运行.正如您所理解的,这是令人沮丧的.此代码不会打印,并且目标函数(以及任何函数)中的每个测试打印都不会执行;它只是被跳过了.

I have a problem and I can't figure out what the issue is. The embedded code (the simplest sample code from the 3.2 docs, just to try to debug) WILL NOT run the target function. The Process completes, the program imports and runs without error, Python 3.2 is correctly installed and the directory added to the Path environment variable. I am running the program from IDLE with f5, and every other bit of code works perfectly, however the code within the target function 'f' (in this case) SIMPLY DOES NOT RUN. As you can understand, this is suuuuper frustrating. This code will not print, and every test print within the target function (as well as any function) simply does not execute; it is simply skipped over.

#!/usr/bin/env python
from multiprocessing import Process

def f(name):
    print('hello', name)

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()

有什么想法吗?我在 Windows 7 系统上运行 Python 3.2,并且多处理已成功在我的系统上使用 Python 2.7 运行(尽管我的项目确实需要我在 3.2 中进行开发).很抱歉这么简单的问题,我想一定是路径问题,但我不确定我可能需要做什么才能使这项工作顺利进行,并且无法从 Google 找到任何解决方案,因为 Python 肯定会识别该包(并且拼写错误时失败);它只是行为不正确.感谢您的帮助/建议!!

Any thoughts? I'm running Python 3.2 on a Windows 7 system, and multiprocessing has successfully run on my system with Python 2.7 (though my project DOES require me to develop in 3.2). Sorry for such a simple problem which I imagine must be some path problem, but I'm just not sure what I might have to do to make this work and couldn't find any solution from Google, since Python certainly recognizes the package (and fails when it's misspelled); it just doesn't behave correctly. Thanks for any help/advice!!

推荐答案

Multiprocessing 和 IDLE 不能很好地协同工作.确保它在 IDLE 之外运行,如果是这样,你就很好.

Multiprocessing and IDLE don't work well together. Make sure it runs outside IDLE, and if so, you're good.

我自己不使用 IDE,所以我没有其他人可以提供给您,但令人惊讶的是,简单的 print 可以用于调试.

I don't use IDEs myself so I have no others to offer you, but it is amazing how useful simple prints can be for debugging.

这篇关于Python 3.2 Multiprocessing.Process 未运行目标函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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