Python IDLE 子进程错误?

发布于 2024-07-20 20:24:07 字数 538 浏览 4 评论 0原文

IDLE的子进程没有执行 联系。 IDLE 无法启动 子进程或个人防火墙 软件正在阻止连接。

不要以为这个问题已经被问到了——为什么在运行非常简单的程序时偶尔会出现这个问题——然后我必须去任务管理器和任务管理器? 停止所有 Pythonw 进程以使其再次工作?

它似乎在不同的代码位上随机发生 - 这是我现在正在做的 -

f = open('money.txt')
currentmoney = float(f.readline())
print(currentmoney, end='')
howmuch = (float(input('How much did you put in or take out?:')))
now = currentmoney + howmuch
print(now)
f.close()
f = open('money.txt', 'w')
f.write(str(now))
f.close()

有时它有效,有时它不起作用!

IDLE's subprocess didn't make
connection. Either IDLE can't start a
subprocess or personal firewall
software is blocking the connection.

Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager & stop all Pythonw processes to get it to work again?

It seems to happen randomnly on different bits of code-here is the one I'm doing at the moment-

f = open('money.txt')
currentmoney = float(f.readline())
print(currentmoney, end='')
howmuch = (float(input('How much did you put in or take out?:')))
now = currentmoney + howmuch
print(now)
f.close()
f = open('money.txt', 'w')
f.write(str(now))
f.close()

Sometimes it works, sometimes it doesn't!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

哑剧 2024-07-27 20:24:07

我收到了同样的错误消息。 对我来说造成问题的是我将我的脚本之一命名为“string.py”。 每次我尝试在同一目录中运行带有“string.py”的脚本时,都会发生这种情况。

I was getting the same error message. What was causing the problem for me was that I named one of my scripts 'string.py'. Every time I tried to run a script with 'string.py' in the same directory this happened.

¢好甜 2024-07-27 20:24:07

您可以使用idle -n来避免此类问题(尽管可能会受到一些其他限制)。

You can use idle -n to avoid such issues (albeit possibly getting some other limitations).

雾里花 2024-07-27 20:24:07

我在 2.7.3 中也遇到了同样的问题。 我发现当我学习如何使用 tkinter 并制作了一个打开窗口的基本程序时,我将其命名为 Tkinter.py 并将其放在与我尝试使用 IDLE 运行的程序相同的文件夹中。 它总是会编译名为 Tkinter 的程序并生成第二个编译文件。 当我尝试运行其他程序时,我会收到错误消息。 我将简单的 Windows 打开程序重命名为其他名称,并删除了编译的文件。 我能够在 IDLE 状态下运行该文件夹中的每个程序,没有任何问题。

I had this same problem in 2.7.3. I found that when I was learning how to use tkinter and I made a basic program to open a window, I named it Tkinter.py and put it in the same folder as the program I was trying to run with IDLE. It would always compile the program called Tkinter and make a second compiled file. When I tried to run my other program I would get the error message. I renamed my simple windows-opening program to something else and deleted the compiled file. I was able to run every program in that folder with IDLE no problem.

今天小雨转甜 2024-07-27 20:24:07

在 Python 3.0.1 中,我在 Idle 的 Python Shell 中使用 Ctrl-C 中断之前运行的程序然后尝试运行脚本后遇到了该错误。

同样在 3.0.1 中:假设您打开了两个 Idle 窗口:一个打开用于编辑的脚本,以及 Idle 的 Python Shell 窗口。 我发现,如果您关闭 shell 窗口,然后立即尝试运行脚本,当它尝试重新打开 shell 时,它会给出该错误 - 但如果您在中间稍等一下,让 Idle 执行任何连接清理,则不会出现该错误起来它需要做的。

我发现了更严重的错误(同样,在 v3.0.1 中 - 不确定这是否会在 2.x 版本中发生):
我有一个很长的脚本 - 接近 9k 行 - 一旦它达到一定大小,对其执行“另存为”操作就会导致空闲崩溃。 我不确定大小的确切阈值是多少 - 但在此之前,我还会遇到一些间歇性的“另存为”崩溃,这似乎取决于我正在进行的其他操作 - 其他空闲窗口​​,外壳中有多少输出也许是窗户——类似的东西。 它可能会崩溃,您将丢失未保存的工作。

另外 - 我经常做的一件事是打开一个临时窗口,在其中剪切和粘贴各个有效性阶段的代码,给自己写注释等 - 所以不是有效的 python 脚本,但我有时会保存这些以便我可以来回到他们身边。 我有一个这样的文件,每次我尝试打开它时,它都会在空闲状态下崩溃 - 而且我第一次丢失了未保存的工作。 (仅供参考:包括 PythonWin 2.5.2 在内的其他编辑器打开该文件没有问题。)

In Python 3.0.1, I have gotten that error after I Ctrl-C to interrupt a previous run of a program in Idle's Python Shell and then try to run a script.

Also in 3.0.1: Let's say you have two Idle windows open: a script open for editing in one, and Idle's Python Shell window. I have found that if you close the shell window and then immediately try to run the script, it will give that error when it tries to re-open the shell - but not if you wait a bit in between to let Idle do whatever connection clean up it needs to do.

Worse bugs I have found (again, in v3.0.1- not sure if this would happen in the 2.x versions):
I had a long script - getting up towards 9k lines - and once it got to a certain size, doing "save as" on it would crash Idle. I am not sure what the exact threshold was for size - but before that, I would also get some intermittent "save as" crashes that seemed to depend on what else I had going on - other Idle windows, how much output was in the shell window perhaps - stuff like that. It can crash and you will lose unsaved work.

Also - one thing I commonly do is have a scratch window open where I cut and paste bits of code in various stages of validity, write notes to myself, etc - so not a valid python script, but I sometimes save these so I can come back to them. I have one such file that will crash Idle every time I try to open it - and I lost unsaved work the first time. (FYI: Other editors including PythonWin 2.5.2 have no problem opening the file.)

浊酒尽余欢 2024-07-27 20:24:07

您能提供一个简短的代码示例来更具体吗?

IDLE 有一些线程问题。 因此,调试问题的第一件事是在子进程中打印一些简单的内容。 从而您将看到这是否是网络或线程相关的问题。

Can you be more specific by providing a short code sample?

IDLE has some threading issues. So the first thing to debug your problem would be to print some simple stuff in your subprocess. Thereby you will see whether it is a network or threading related issue.

人│生佛魔见 2024-07-27 20:24:07

简单的。 只需剪切所有扩展名为 .py 的文件,将它们粘贴到与操作系统路径不同的位置,其中一个文件会导致此类错误。 再次运行 IDLE。

Simple. Just cut all files with .py extension, paste them in a place different from the os path, one of the files is causing such error. Run the IDLE again.

椒妓 2024-07-27 20:24:07

如果它看起来像真正的随机行为,那么它可能是多 CPU/核心问题。
您可以尝试将解释器亲和力设置为固定CPU,看看这个问题是否仍然出现。

谷歌搜索类似:imagecfg processaffinity
欲了解更多相关信息。

If it look like truly random behavior than it could be a multi-cpu/core issue.
You could try to set the interpreter affinity to a fixed cpu and see if this issue still comes up.

Google for something like: imagecfg process affinity
For more information about that.

罗罗贝儿 2024-07-27 20:24:07

我有同样的错误。 我重新启动了调制解调器,令我惊讶的是,它成功了!

i had the same error. I did a modem reboot and to my surprise, it worked !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文