gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:01 25 4
gpt4 key购买 nike

我已经更新了这个问题,以在不是从 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),出现一条弹出消息(标题为“Python for Win32”)说“无法从 -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、Python 2.6.4v 上运行它

最佳答案

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

关于python - 无法在 PythonWin 中运行任何多处理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4563757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com