Python IDLE becomes slow on very large program input

空扰寡人 提交于 2019-12-20 03:26:10

问题


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

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


回答1:


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
~$ 

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.

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 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.

Conclusion

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



来源:https://stackoverflow.com/questions/18271170/python-idle-becomes-slow-on-very-large-program-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!