def test_unexpectedOSError(self):
        """
        An unexpected L{OSError} when checking the validity of a
        PID in a C{pidfile} terminates the process via L{SystemExit}.
        """
        pidfile = self.mktemp()
        with open(pidfile, "w") as f:
            f.write("3581")
        def kill(pid, sig):
            raise OSError(errno.EBADF, "fake")
        self.patch(os, "kill", kill)
        e = self.assertRaises(SystemExit, checkPID, pidfile)
        self.assertIsNot(e.code, None)
        self.assertTrue(e.args[0].startswith("Can't check status of PID"))

        An unexpected L{OSError} when checking the validity of a
        PID in a C{pidfile} terminates the process via L{SystemExit}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py