[Python-Dev] Details on Python shutting down

Brett C. drifty@alum.berkeley.edu
Sun, 15 Jun 2003 23:24:11 -0700


On bug #754449 I suspected something was being set to None by a person's 
app and ended up writing a trace function to catch when that happened. 
Time then stepped in and pointed out that the OP said when Python was 
shutting down and that globals are set to None during tear down which 
would explain the behavior.  He suggested I move this over to python-dev.

So, what exactly does Python do during shutdown?  I assume all objects 
get cleaned up and have their __del__ methods called if they have them. 
  Tim mentioned in the patch that Python "systematically sets 
module-global bindings to None".  So I assume this means that 
referencing *any* globals during shutdown just doesn't work since it 
might be None (which makes sense in the case of this bug report).  Is 
there any specific order to this teardown?  I remember Tim saying that 
in __del__ methods you had to have locally bound anything you needed to 
call since otherwise it could be gone when you need it.

Any words of wisdom here would be greatly appreciated.

-Brett