Mailing List Archive

IDLE's PyShell
Just noticed that IDLE's interactive shell eats an unusually big
amount of memory. Just pressing the RETURN key a couple of times,
or even better ;-) -- closing and reopening the PyShell window
does not seem to reuse the prevously allocated memory...

I'm very far from this code, so don't blame me for not proposing a
patch, but here are two things I experimented with that seem to help
partially:

1. Clear the linecache when closing the PyShell window
2. Finalize properly the undo machinery in EditorWindow
(yes -- the XXX sign is there to remind that the _close
method needs more work regarding undo)
For instance, I tried to finalize undo before self.io.close
which seemed to work.

This helps a bit, but still a repeted open/close of PyShell eats
(less) memory. Sorry for not being able to help you more at this stage,
IDLE hackers! (ah, forgot to mention -- I refer to the latest version,
the one in the CVS tree).

--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252
IDLE's PyShell [ In reply to ]
[Vladimir Marangozov]
> Just noticed that IDLE's interactive shell eats an unusually big
> amount of memory. Just pressing the RETURN key a couple of times,
> or even better ;-) -- closing and reopening the PyShell window
> does not seem to reuse the prevously allocated memory...

Christian (Tismer) ruined my life several weeks ago by noting that if he
typed

sys.getrefcount(None)

in the IDLE shell, it kept going up & up & up as windows were opened and
closed. That's a pretty good sign of A Leak. The CVS version has plugged
many leaks, and I just submitted a brief patch to plug 3 more, but it's
still leaking. At least *closing* a window no longer boosts None's
refcount! Opening one does, though.

> I'm very far from this code, so don't blame me for not proposing a
> patch, but here are two things I experimented with that seem to help
> partially:
>
> 1. Clear the linecache when closing the PyShell window

Submit a patch!

> 2. Finalize properly the undo machinery in EditorWindow
> (yes -- the XXX sign is there to remind that the _close
> method needs more work regarding undo)
> For instance, I tried to finalize undo before self.io.close
> which seemed to work.

Not sure that one's a problem anymore; the undo machinery doesn't show up on
the list of live objects at the end for me anymore. The Tk Text instance
still does, though, and that's a biggie.

just-stop-opening-and-closing-the-shell<wink>-ly y'rs - tim
IDLE's PyShell [ In reply to ]
Tim Peters wrote:
>
> > I'm very far from this code, so don't blame me for not proposing a
> > patch, but here are two things I experimented with that seem to help
> > partially:
> >
> > 1. Clear the linecache when closing the PyShell window
>
> Submit a patch!

If I knew where's the appropriate place to put the linecache.clearcache()
function call, I would have submitted a patch. But I don't know very well
the shell logic, so I'll let somebody else do it for me.

Actually, I really don't understand very well how the PyShell works.
Here's another little exercise that causes some weird behavior. If you can
reproduce it, then it's most probably a bug unrelated to my personal install.

1) start a brand new idle.py (the PyShell welcomes you to Pythonland)
2) press RETURN a couple of times (just to warm the linecache ;-)
3) See the contents of the cache dict by typing "PyShell.linecache.cache"
4) Now provoke a name error by typing, say, "bonk"

we get the usual Traceback ... NameError: bonk.
Everything seems to be perfect, until...

5) See again the contents of the cache with PyShell.linecache.cache

I get a huge output, containing the entire PyShell.py source...
With all due respect to PyShell.py, its source shouldn't be there, isn't it?

--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252
IDLE's PyShell [ In reply to ]
Vladimir Marangozov wrote in message <3795F12D.91B820BB@inrialpes.fr>...

>function call, I would have submitted a patch. But I don't know very well
>the shell logic, so I'll let somebody else do it for me.

As long as you arent holding your breath, you should be fine :-) OTOH,
maybe this is a good way to learn the shell logic. No one in the world
understood the PyShell logic when released except the author (Guido). The
rest of us had to read the source like you do.

>I get a huge output, containing the entire PyShell.py source...
>With all due respect to PyShell.py, its source shouldn't be there, isn't
it?

Why does this bother you? This is an implementation detail of IDLE. Its
downside is the memory usage, but the upside is that IDLE works.

Unless this is causing you a specific problem, then why worry?

Mark.
IDLE's PyShell [ In reply to ]
Tim Peters wrote:
>
> just-stop-opening-and-closing-the-shell<wink>-ly y'rs - tim

Easier said than done when the "flatten" and "close"
gadgets are so close together up there in the corner
of the window. It's very easy to hit the wrong one
in the heat of battle.

By the way, is there any way to create a window that
doesn't have, for example, a close gadget? I think
I've seen windows like that in other Windows apps,
but I can't find any way of doing it in Tkinter.
I'd really like to expunge the close gadgets from
my modal dialogues -- they're so utterly useless
there...

Greg
IDLE's PyShell [ In reply to ]
[Vladimir Marangozov]
> ...
> Actually, I really don't understand very well how the PyShell works.

Then you understand it a lot better than I do <0.7 wink>.

> Here's another little exercise that causes some weird behavior. If you can
> reproduce it, then it's most probably a bug unrelated to my
> personal install.
>
> 1) start a brand new idle.py (the PyShell welcomes you to Pythonland)
> 2) press RETURN a couple of times (just to warm the linecache ;-)
> 3) See the contents of the cache dict by typing "PyShell.linecache.cache"
> 4) Now provoke a name error by typing, say, "bonk"
>
> we get the usual Traceback ... NameError: bonk.
> Everything seems to be perfect, until...
>
> 5) See again the contents of the cache with PyShell.linecache.cache
>
> I get a huge output, containing the entire PyShell.py source...

Yes, that happens for me too.

> With all due respect to PyShell.py, its source shouldn't be
> there, isn't it?

I don't know! linecache.py predates IDLE's existence, and every time I've
bumped into it it seemed like an optimization that created more problems
than it solved. So if I were to pursue this, I'd look harder at tossing it
than fixing it.

But then I'm not sure why it's there either. I expect that in your case,
it's actually traceback.py that's stuffing all of PyShell.py into the
linecache, as part of formatting the NameError exception, snaking thru
InteractiveInterpreter.showtraceback. That last is hiding from you that
PyShell.py is in the true NameError traceback (you see an edited version of
it by the time it gets to the shell window).

now-you-understand-it-better-than-i-do<wink>-ly y'rs - tim
IDLE's PyShell [ In reply to ]
Greg Ewing <greg.ewing@compaq.com> writes:

>By the way, is there any way to create a window that
>doesn't have, for example, a close gadget? I think
>I've seen windows like that in other Windows apps,
>but I can't find any way of doing it in Tkinter.

Try

f = Tk.Toplevel()
f.transient(parent)

to get a window without the close button - /F has some documentation on this at
http://www.pythonware.com/library/tkinter/introduction/x8886-style-methods.htm

Mark
--
Email - mark@chem.uwa.edu.au ,-_|\ Mark C Favas
Phone - +61 9 380 3482 / \ Department of Chemistry
Fax - +61 9 380 1005 ---> *_,-._/ The University of Western Australia
v Nedlands
Loc - 31.97 S, 115.81 E Western Australia 6009
IDLE's PyShell [ In reply to ]
Mark C Favas wrote:
>
> f = Tk.Toplevel()
> f.transient(parent)
>
> to get a window without the close button

Doesn't work for me. It gets rid of the fullscreen
and iconify buttons, but it still has a close button.

Greg