Speeding up Python's exit

Antoine Pitrou solipsis at pitrou.net
Fri Mar 1 09:59:29 EST 2013


Steven D'Aprano <steve+comp.lang.python <at> pearwood.info> writes:
> 
> I just quit an interactive session using Python 2.7 on Linux. It took in 
> excess of twelve minutes to exit, with the load average going well past 9 
> for much of that time.
> 
> 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). 
> 
> Can anyone explain why this was so painfully slow, and what (if anything) 
> I can do to avoid it in the future?

You are basically asking people to guess where your performance problem
comes from, without even providing a snippet so that people can reproduce ;)

> I know there is a function os._exit which effectively kills the Python 
> interpreter dead immediately, without doing any cleanup. What are the 
> consequences of doing this? I assume that the memory used by the Python 
> process will be reclaimed by the operating system, but other resources 
> such as opened files may not be.

The OS always disposes of per-process resources when the process terminates
(except if the OS is buggy ;-)). However, file buffers will not be flushed,
atexit handlers and other destructors will not be called, database
transactions will be abandoned (rolled back), etc.

Regards

Antoine.





More information about the Python-list mailing list