[CalendarServer-changes] [14404] twext/trunk/twext/who/opendirectory/_service.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 12 12:39:10 PST 2015
Revision: 14404
http://trac.calendarserver.org//changeset/14404
Author: sagen at apple.com
Date: 2015-02-12 12:39:10 -0800 (Thu, 12 Feb 2015)
Log Message:
-----------
Make sure OD service only has a single AutoReleasePool
Modified Paths:
--------------
twext/trunk/twext/who/opendirectory/_service.py
Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py 2015-02-11 20:34:55 UTC (rev 14403)
+++ twext/trunk/twext/who/opendirectory/_service.py 2015-02-12 20:39:10 UTC (rev 14404)
@@ -165,6 +165,9 @@
fieldName = ConstantsContainer((BaseDirectoryService.fieldName, FieldName))
+ # The auto release pool is a class attribute; if _poolDeletionRegistered
+ # is True, that means someone has already added a SystemEventTrigger
+ _poolDeletionRegistered = False
def __init__(
self,
@@ -184,42 +187,47 @@
# Create an autorelease pool which will get deleted when someone
- # calls _maybeDrainPool( ), but no more often than 60 seconds, hence
+ # calls _maybeResetPool( ), but no more often than 60 seconds, hence
# the "maybe"
- self._resetAutoreleasePool()
+ DirectoryService._resetAutoreleasePool()
# Register a pool delete to happen at shutdown
- from twisted.internet import reactor
- reactor.addSystemEventTrigger("after", "shutdown", self._deletePool)
+ if not DirectoryService._poolDeletionRegistered:
+ from twisted.internet import reactor
+ DirectoryService._poolDeletionRegistered = True
+ reactor.addSystemEventTrigger("after", "shutdown", DirectoryService._deletePool)
- def _deletePool(self):
+ @classmethod
+ def _deletePool(cls):
"""
Delete the autorelease pool if we have one
"""
- if hasattr(self, "_autoReleasePool"):
- del self._autoReleasePool
+ if hasattr(cls, "_autoReleasePool"):
+ del cls._autoReleasePool
- def _resetAutoreleasePool(self):
+ @classmethod
+ def _resetAutoreleasePool(cls):
"""
Create an autorelease pool, deleting the old one if we had one.
"""
- self._deletePool()
+ cls._deletePool()
- self._autoReleasePool = NSAutoreleasePool.alloc().init()
- self._poolCreationTime = time()
+ cls._autoReleasePool = NSAutoreleasePool.alloc().init()
+ cls._poolCreationTime = time()
- def _maybeResetPool(self):
+ @classmethod
+ def _maybeResetPool(cls):
"""
If it's been at least 60 seconds since the last time we created the
pool, delete the pool (which drains it) and create a new one.
"""
- poolCreationTime = getattr(self, "_poolCreationTime", 0)
+ poolCreationTime = getattr(cls, "_poolCreationTime", 0)
now = time()
if (now - poolCreationTime) > 60:
- self._resetAutoreleasePool()
+ cls._resetAutoreleasePool()
@@ -826,7 +834,7 @@
self, expression, recordTypes=None, records=None,
limitResults=None, timeoutSeconds=None
):
- self._maybeResetPool()
+ DirectoryService._maybeResetPool()
if isinstance(expression, MatchExpression):
@@ -866,7 +874,7 @@
CompoundExpression up into MatchExpressions for sending to the local
node.
"""
- self._maybeResetPool()
+ DirectoryService._maybeResetPool()
try:
self.log.debug("OD call: {}".format(expression))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150212/3df172cf/attachment.html>
More information about the calendarserver-changes
mailing list