Speeding up Python's exit

Chris Angelico rosuav at gmail.com
Thu Feb 28 12:06:39 EST 2013


On Fri, Mar 1, 2013 at 3:49 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I think the reason it took so long was that Python was garbage-collecting
> a giant dict with 10 million entries, each one containing a list of the
> form [1, [2, 3], 4]. But still, that's terribly slow -- ironically, it
> took longer to dispose of the dict (12+ minutes) than it took to create
> it in the first place (approx 3 minutes, with a maximum load of 4).

Leaving the question of just *why* you have so much in your dict.....
but anyway.

Is it any different if you create a deliberate reference loop and then
stuff it into some module somewhere? That would force it to be kept
until interpreter shutdown, and then a cyclic garbage collection after
that, which quite probably would be never run. A stupid trick,
perhaps, but it might work; I tested it with a dummy class with a
__del__ method and it wasn't called. Putting it into some other module
may not be necessary, but I don't know what happens with the
interactive interpreter and what gets freed up when.

ChrisA



More information about the Python-list mailing list