Ticket #2066: 2066.patch

File 2066.patch, 2.7 KB (added by mishok13, 5 years ago)

First attempt at the actual fix

  • twisted/internet/base.py

    diff --git twisted/internet/base.py twisted/internet/base.py
    index 69dd3b4..d96bcbf 100644
    class ReactorBase(object): 
    471471        self.running = False
    472472        self._started = False
    473473        self._justStopped = False
     474        self._startedBefore = False
    474475        # reactor internal readers, e.g. the waker.
    475476        self._internalReaders = set()
    476477        self.waker = None
    class ReactorBase(object): 
    570571                "Can't stop reactor that isn't running.")
    571572        self._stopped = True
    572573        self._justStopped = True
     574        self._startedBefore = True
    573575
    574576
    575577    def crash(self):
    class ReactorBase(object): 
    668670        """
    669671        if self._started:
    670672            raise error.ReactorAlreadyRunning()
     673        if self._startedBefore:
     674            raise error.ReactorNotRestartable()
    671675        self._started = True
    672676        self._stopped = False
    673677        threadable.registerAsIOThread()
  • twisted/internet/error.py

    diff --git twisted/internet/error.py twisted/internet/error.py
    index aa40faf..47667c0 100644
    class ReactorNotRunning(RuntimeError): 
    350350    """
    351351
    352352
     353class ReactorNotRestartable(RuntimeError):
     354    """
     355    Error raised when trying to run a reactor which was stopped.
     356    """
     357
     358
    353359
    354360class ReactorAlreadyRunning(RuntimeError):
    355361    """
  • twisted/internet/test/test_core.py

    diff --git twisted/internet/test/test_core.py twisted/internet/test/test_core.py
    index 75592b4..6eb7aaa 100644
    import time 
    1212import inspect
    1313
    1414from twisted.internet.abstract import FileDescriptor
    15 from twisted.internet.error import ReactorAlreadyRunning
     15from twisted.internet.error import ReactorAlreadyRunning, ReactorNotRestartable
    1616from twisted.internet.defer import Deferred
    1717from twisted.internet.test.reactormixins import ReactorBuilder
    1818
    class SystemEventTestsBuilder(ReactorBuilder): 
    310310        self.assertEqual(events, ['crash', ('stop', True)])
    311311
    312312
     313    def test_runAfterStop(self):
     314        """
     315        C{reactor.run()} raises L{ReactorNotRestartable} when called when
     316        the reactor is being run after getting stopped priorly.
     317        """
     318        events = []
     319        def restart():
     320            self.assertRaises(ReactorNotRestartable, reactor.run)
     321            events.append('tested')
     322        reactor = self.buildReactor()
     323        reactor.callWhenRunning(reactor.stop)
     324        reactor.addSystemEventTrigger('after', 'shutdown', restart)
     325        reactor.run()
     326        self.assertEqual(events, ['tested'])
     327
     328
     329
    313330globals().update(SystemEventTestsBuilder.makeTestCaseClasses())
    314331globals().update(ObjectModelIntegrationTest.makeTestCaseClasses())