WeakRefs, callbacks and GC when program quits

Daniel Shane daniel_shane_eicon_junk at hotmail.com
Wed Aug 7 12:03:07 EDT 2002


I'm having some problems with weakrefs and callbacks in regards to
program termination in 2.2.1. It seems that whenever a python script
ends, all variables are "deleted" and if any weakrefs are still there
with callbacks registered, they will be called in the process.

Unfortunately, this can lead to some errors because I believe that the
memory content at that time is uncertain. Therefore, I surely think
that we should have a way to tell weakref not to call the callbacks at
program termination (or maybe this should be the defacto behavior). In
my case, I got this error message when weakref attempted to execute a
callback when the script ended (because the GC started to reap all
local/global variables):

Exception exceptions.SystemError: 'codec module not properly
initialized' when attempting to access a method in the class that
defined the callback.

I propose to add a method in weakref called clear_all_callbacks that
could be called to ensure that no callbacks will be called upon
termination.

What do you think?

Regards,
Daniel Shane
--
Daniel Shane
GNU/Linux Developer



More information about the Python-list mailing list