Python IDLE becomes slow on very large program inp

2019-02-26 16:34发布

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条回答
相关推荐>>
2楼-- · 2019-02-26 17:34

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.

查看更多
登录 后发表回答