无法在PythonWin中运行任何多处理脚本

无法在PythonWin中运行任何多处理脚本,python,multiprocessing,Python,Multiprocessing,我已经更新了这个问题,以在一个多处理脚本中显示我的问题,该脚本不是从PythonWin运行的(通过按F5),而是从命令提示符运行的。 我的剧本:- """ File Name: simple multiprocess example.py Description: A very basic multiprocessing script to show the use of daemon. There are two processes:- p1 - calls listen() and runs

我已经更新了这个问题,以在一个多处理脚本中显示我的问题,该脚本不是从PythonWin运行的(通过按F5),而是从命令提示符运行的。 我的剧本:-

"""
File Name: simple multiprocess example.py
Description:
A very basic multiprocessing script to show the use of daemon.
There are two processes:-
p1 - calls listen() and runs in the background (daemon = True)
p2 - calls write()
"""
import multiprocessing
import time
import sys

def listen():
    p = multiprocessing.current_process()
    p_name = str(p.name)
    pid = str(p.pid)
    while 1:
        print "%s process with PID %s running: %s" % (p_name, pid, time.asctime())
        time.sleep(1)
    print 'Exiting :', p.name, p.pid

def write():
    p = multiprocessing.current_process()
    p_name = str(p.name)
    pid = str(p.pid)
    for x in xrange(3):
        print "%s process with PID %s running: %s" % (p_name, pid, time.asctime())
        time.sleep(1)
    print 'Exiting :', p.name, p.pid

if __name__ == '__main__':
    p1 = multiprocessing.Process(name='listen', target=listen)
    p1.daemon = True

    p2 = multiprocessing.Process(name='write', target=write)
    p2.daemon = False

    p1.start()

    p2.start()
    time.sleep(7)
当我从PythonWin运行上述脚本时(按F5),弹出一条消息(标题为“pythonforwin32”)说“无法从-c加载文件” 其中是具有完整路径的文件名

当我从命令提示符运行同一个脚本时,它似乎运行得非常完美,没有任何问题。在命令提示符下运行时,我得到以下输出:-

s>"simple multiprocess example.py"
listen process with PID 4564 running: Tue Jan 04 09:32:49 2011
write process with PID 3744 running: Tue Jan 04 09:32:49 2011
listen process with PID 4564 running: Tue Jan 04 09:32:50 2011
write process with PID 3744 running: Tue Jan 04 09:32:50 2011
listen process with PID 4564 running: Tue Jan 04 09:32:51 2011
write process with PID 3744 running: Tue Jan 04 09:32:51 2011
listen process with PID 4564 running: Tue Jan 04 09:32:52 2011
Exiting : write 3744
listen process with PID 4564 running: Tue Jan 04 09:32:53 2011
listen process with PID 4564 running: Tue Jan 04 09:32:54 2011
listen process with PID 4564 running: Tue Jan 04 09:32:55 2011
我在网上找不到与此问题相关的任何内容。 谢谢你的帮助

阿米特 附笔:
我在Windows XP、PythonWin、Python2.6.4v上运行它,您需要将要运行的代码保存在.py文件中。多处理不支持执行仅在交互模式下输入的代码。

您需要将要运行的代码保存在.py文件中。多处理不支持执行仅在交互模式下输入的代码。

谢谢您的回复。但是,即使我将这些代码集放在python文件中并按F5运行该python文件,也会出现相同的错误。请确保主代码位于
if
块中。如果这没有帮助:发布您试图运行的完整代码。我在main中有这些代码。我也更新了问题。如果你得到答案,请告诉我?谢谢你,阿米特谢谢你的回复。但是,即使我将这些代码集放在python文件中并按F5运行该python文件,也会出现相同的错误。请确保主代码位于
if
块中。如果这没有帮助:发布您试图运行的完整代码。我在main中有这些代码。我也更新了问题。如果你得到答案,请告诉我?谢谢,阿米特