[Zope3-checkins] SVN: Zope3/trunk/src/zope/thread/__init__.py Added
a number of error checks and globar variable caches in __del__
Jim Fulton
jim at zope.com
Fri Jul 9 19:36:04 EDT 2004
Log message for revision 26386:
Added a number of error checks and globar variable caches in __del__
to try to avoid error during process exit. __del__s are a pain.
-=-
Modified: Zope3/trunk/src/zope/thread/__init__.py
===================================================================
--- Zope3/trunk/src/zope/thread/__init__.py 2004-07-09 23:06:06 UTC (rev 26385)
+++ Zope3/trunk/src/zope/thread/__init__.py 2004-07-09 23:36:04 UTC (rev 26386)
@@ -215,12 +215,37 @@
lock.release()
- def __del__(self, enumerate=enumerate):
- key = object.__getattribute__(self, '_local__key')
- for thread in enumerate():
- if key in thread.__dict__:
- del thread.__dict__[key]
+ def __del__():
+ threading_enumerate = enumerate
+ __getattribute__ = object.__getattribute__
+ def __del__(self):
+ key = __getattribute__(self, '_local__key')
+
+ try:
+ threads = list(threading_enumerate())
+ except:
+ # if enumerate fails, as it seems to do during
+ # shutdown, we'll skip cleanup under the assumption
+ # that there is nothing to clean up
+ return
+
+ for thread in threads:
+ try:
+ __dict__ = thread.__dict__
+ except AttributeError:
+ # Thread is dying, rest in peace
+ continue
+
+ if key in __dict__:
+ try:
+ del __dict__[key]
+ except KeyError:
+ pass # didn't have nything in this thread
+
+ return __del__
+ __del__ = __del__()
+
else:
local = _zope_thread.local
del _zope_thread
More information about the Zope3-Checkins
mailing list