Python IDLE freezes

2019-02-18 22:54发布

问题:

This is absolutely frustrating, but I am not sure if the following is an issue only on my machine or with IDLE in general.

When attempting to print a long list in the shell, and that could happen by accident while debugging, the program crushes and you have to restart it manually.

Even worse, if you have a few editor windows open, it always spawns a few sub-processes, and each of these has to be manually shut down from the task manager.

Is there any way to avoid that?

I am using Python 3, by the way.

回答1:

The Squeezer extension addresses this problem. Instead of displaying the long text (which is the source of the slow-down), Squeezer captures the output and displays a button instead. You have the option of expanding the contents or viewing it in Notepad.

Squeezer is included in IdleX, which you may find useful.



回答2:

It seems tk needs to write a lot of data in the shell frame, this takes a lot of time and when the list is long then it becomes unresponsive.

I did:

>>a = range(n)
>>print(list(a))

It was OK for n = 100 or n = 1000. After that point things started being slow. For n as low as 10000, moving the page up and down becomes very, very slow.

I suspect that there is no solution. For small values of n probably it would help to clear() the window but unfortunately idle have not implemented any method to clear the shell. I dont understand why because it should not be difficult...

Edit 2012: During the last months IDLE behavior and functionality got many important improvements through the collection of extensions and plugins provided by IdleX .
Accidental printing of high amounts of data is not a problem anymore. When IdleX detects such a situation it shows a warning indicating the existence of the data instead of printing it. Righ-clicking on the warning produces a preview of the data, not in idle shell but on the system text editor (notepad in windows). In this way the shell doesnt get cluttered with data nor slow down.