Ticket #5151: issue-5151-1.diff

File issue-5151-1.diff, 2.6 KB (added by hodgestar, 3 years ago)

Single patch with fix, test and NEWS update.

  • twisted/internet/_baseprocess.py

     
    3434                _missingProcessExited % (qual(self.proto.__class__),), 
    3535                DeprecationWarning, stacklevel=0) 
    3636        else: 
    37             processExited(Failure(reason)) 
     37            try: 
     38                processExited(Failure(reason)) 
     39            except: 
     40                err(None, "unexpected error in processExited") 
    3841 
    3942 
    4043    def processEnded(self, status): 
  • twisted/internet/test/test_process.py

     
    298298        self.runReactor(reactor) 
    299299 
    300300 
     301    def test_processExitedRaises(self): 
     302        """ 
     303        Test that a protocol raising an exception inside processExited 
     304        doesn't cause the reactor to explode. 
     305        """ 
     306        reactor = self.buildReactor() 
     307 
     308        class TestException(Exception): 
     309            pass 
     310 
     311        class Protocol(ProcessProtocol): 
     312            def processExited(self, reason): 
     313                reactor.callLater(0.01, lambda: reactor.stop()) 
     314                raise TestException("processedExited raised") 
     315 
     316        protocol = Protocol() 
     317        transport = reactor.spawnProcess( 
     318               protocol, sys.executable, [sys.executable, "-c", ""], 
     319               usePTY=self.usePTY) 
     320        reactor.run() 
     321        self.flushLoggedErrors() 
     322 
     323        # Manually clean-up broken process handler 
     324        for pid, handler in process.reapProcessHandlers.items(): 
     325            if handler is not transport: 
     326                continue 
     327            process.unregisterReapProcessHandler(pid, handler) 
     328            self.fail("After processExited raised, transport was left in" 
     329                      " reapProcessHandlers") 
     330 
     331 
    301332class ProcessTestsBuilder(ProcessTestsBuilderBase): 
    302333    """ 
    303334    Builder defining tests relating to L{IReactorProcess} for child processes 
  • NEWS

     
    6969 - twisted.words.services referenced nonexistent 
    7070   twisted.words.protocols.irc.IRC_NOSUCHCHANNEL. This has been fixed. 
    7171   Related code has also received test cases. (#4915) 
     72 - Broken process handlers will no longer be left in the global state 
     73   if a ProcessProtocol raises an exception from within processExited. 
     74   (#5151) 
    7275 
    7376Improved Documentation 
    7477----------------------