Ticket #5522: unbuild-reactor.patch

File unbuild-reactor.patch, 2.1 KB (added by exarkun, 3 years ago)
  • twisted/internet/test/reactormixins.py

     
    1515from twisted.python.reflect import namedAny, fullyQualifiedName 
    1616from twisted.python import log 
    1717from twisted.python.failure import Failure 
     18from twisted.internet.interfaces import IReactorTime 
    1819 
    1920# Access private APIs. 
    2021if platform.isWindows(): 
     
    7778                    "twisted.internet.kqreactor.KQueueReactor", 
    7879                    ]) 
    7980 
     81    _reactors = ["twisted.internet.epollstmreactor.EPollSTMReactor"] 
     82 
    8083    reactorFactory = None 
    8184    originalHandler = None 
    8285    requiredInterfaces = None 
     
    120123        # branch that fixes it. 
    121124        # 
    122125        # -exarkun 
     126        uninstallHandler = getattr(reactor, '_uninstallHandler', None) 
     127        if uninstallHandler is not None: 
     128            uninstallHandler() 
     129 
    123130        reactor._uninstallHandler() 
    124131        if getattr(reactor, '_internalReaders', None) is not None: 
    125132            for reader in reactor._internalReaders: 
     
    127134                reader.connectionLost(None) 
    128135            reactor._internalReaders.clear() 
    129136 
    130         # Here's an extra thing unrelated to wakers but necessary for 
    131         # cleaning up after the reactors we make.  -exarkun 
    132         reactor.disconnectAll() 
     137        disconnectAll = getattr(reactor, 'disconnectAll', None) 
     138        if disconnectAll is not None: 
     139            # Here's an extra thing unrelated to wakers but necessary for 
     140            # cleaning up after the reactors we make.  -exarkun 
     141            disconnectAll() 
    133142 
    134         # It would also be bad if any timed calls left over were allowed to 
    135         # run. 
    136         calls = reactor.getDelayedCalls() 
    137         for c in calls: 
    138             c.cancel() 
     143        if IReactorTime.providedBy(reactor): 
     144            # It would also be bad if any timed calls left over were allowed to 
     145            # run. 
     146            calls = reactor.getDelayedCalls() 
     147            for c in calls: 
     148                c.cancel() 
    139149 
    140150 
    141151    def buildReactor(self):