Ticket #3245: deferred_slots.patch

File deferred_slots.patch, 2.8 KB (added by mgeisler, 9 years ago)

Patch against Twisted SVN r23670

  • twisted/internet/defer.py

     
    121121def passthru(arg):
    122122    return arg
    123123
     124deferred_debug = False
     125
    124126def setDebugging(on):
    125127    """Enable or disable Deferred debugging.
    126128
    127129    When debugging is on, the call stacks from creation and invocation are
    128130    recorded, and added to any AlreadyCalledErrors we raise.
    129131    """
    130     Deferred.debug=bool(on)
     132    global deferred_debug
     133    deferred_debug = bool(on)
    131134
    132135def getDebugging():
    133136    """Determine whether Deferred debugging is enabled.
    134137    """
    135     return Deferred.debug
     138    return deferred_debug
    136139
    137 class Deferred:
     140class Deferred(object):
    138141    """This is a callback which will be put off until later.
    139142
    140143    Why do we want this? Well, in cases where a function in a threaded
     
    149152    For more information about Deferreds, see doc/howto/defer.html or
    150153    U{http://twistedmatrix.com/projects/core/documentation/howto/defer.html}
    151154    """
    152     called = 0
    153     paused = 0
    154     timeoutCall = None
    155     _debugInfo = None
    156155
    157     # Are we currently running a user-installed callback?  Meant to prevent
    158     # recursive running of callbacks when a reentrant call to add a callback is
    159     # used.
    160     _runningCallbacks = False
     156    __slots__ = ['called', 'paused', 'timeoutCall', '_debugInfo', 'result',
     157                 '_runningCallbacks', 'callbacks']
    161158
    162     # Keep this class attribute for now, for compatibility with code that
    163     # sets it directly.
    164     debug = False
     159    def __init__(self):
     160        self.called = 0
     161        self.paused = 0
     162        self.timeoutCall = None
     163        self._debugInfo = None
    165164
    166     def __init__(self):
     165        # Are we currently running a user-installed callback? Meant to
     166        # prevent recursive running of callbacks when a reentrant call
     167        # to add a callback is used.
     168        self._runningCallbacks = False
     169
    167170        self.callbacks = []
    168         if self.debug:
     171        if deferred_debug:
    169172            self._debugInfo = DebugInfo()
    170173            self._debugInfo.creator = traceback.format_stack()[:-1]
    171174
     
    290293
    291294    def _startRunCallbacks(self, result):
    292295        if self.called:
    293             if self.debug:
     296            if deferred_debug:
    294297                if self._debugInfo is None:
    295298                    self._debugInfo = DebugInfo()
    296299                extra = "\n" + self._debugInfo._getDebugTracebacks()
    297300                raise AlreadyCalledError(extra)
    298301            raise AlreadyCalledError
    299         if self.debug:
     302        if deferred_debug:
    300303            if self._debugInfo is None:
    301304                self._debugInfo = DebugInfo()
    302305            self._debugInfo.invoker = traceback.format_stack()[:-2]