[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/thread/__init__.py
Merged from trunk:
Jim Fulton
jim at zope.com
Sat Jul 10 09:24:19 EDT 2004
Log message for revision 26396:
Merged from trunk:
r26386 | jim | 2004-07-09 19:36:04 -0400 (Fri, 09 Jul 2004) | 3 lines
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/branches/ZopeX3-3.0/src/zope/thread/__init__.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/thread/__init__.py 2004-07-10 13:23:35 UTC (rev 26395)
+++ Zope3/branches/ZopeX3-3.0/src/zope/thread/__init__.py 2004-07-10 13:24:18 UTC (rev 26396)
@@ -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