Python IDLE 在非常大的程序输入上变得很慢 [英] Python IDLE becomes slow on very large program input

查看:69
本文介绍了Python IDLE 在非常大的程序输入上变得很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 python idle 在处理非常大的输入时变得如此缓慢,而 python 命令行却没有?

Why does python idle become so slow when handling very large inputs, when the python command line does not?

例如,如果我在 python IDLE 中运行 "aman"*10000000,它变得没有响应,但在 python cmd 行上,它很快.

For example, if I run "aman"*10000000 in python IDLE, it becomes unresponsive, but on python cmd line, it is quick.

推荐答案

我不得不研究一下.当我在我的机器上调用 idle 时,我看到另一个使用 idlelib

I had to research a bit. When I invoked idle on my machine, I saw another python process which uses idlelib

~$ ps -eaf | grep -in idle
234:1000     13122     1  5 16:44 ?        00:00:01 /usr/bin/python2.7 /usr/bin/idle-python2.7
235:1000     13124 13122  3 16:44 ?        00:00:01 /usr/bin/python2.7 -c __import__('idlelib.run').run.main(True) 60839
239:1000     13146 12061  0 16:44 pts/0    00:00:00 grep --color=auto -in idle
~$ 

最后一个参数(60839)让我想到了.所以我四处寻找 idlelib 并在这里得到了实现 https://github.com/pypy/pypy/blob/master/lib-python/2.7/idlelib/run.py#L49 那里的评论说

The last parameter (60839) made me think. So I looked around for idlelib and got the implementation here https://github.com/pypy/pypy/blob/master/lib-python/2.7/idlelib/run.py#L49 The comment there says

Start the Python execution server in a subprocess

    In the Python subprocess, RPCServer is instantiated with handlerclass
    MyHandler, which inherits register/unregister methods from RPCHandler via
    the mix-in class SocketIO.

现在,事情对我来说很清楚了.IDLE 通过 TCP 连接向 python 解释器发送命令.尽管如此,我还是不相信.然后我阅读了完整的Help->About IDLE->README.它说

Now, things were clear to me. The IDLE sends commands to python interpreter over a TCP connection. Still, I am not convinced. Then I read the complete Help->About IDLE->README. It says

IDLE 在单独的进程中执行 Python 代码,该进程会重新启动对于从编辑器窗口启动的每个运行 (F5).环境也可以在不重启 IDLE 的情况下从 Shell 窗口重启.

IDLE executes Python code in a separate process, which is restarted for each Run (F5) initiated from an editor window. The environment can also be restarted from the Shell window without restarting IDLE.

结论

当我们有这样的依赖(IDLE 依赖于套接字的响应)时,你所经历的延迟是完全没问题的.

When we have such a dependency (IDLE depending on response over a socket), the delay what you experienced is perfectly fine.

这篇关于Python IDLE 在非常大的程序输入上变得很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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