def checkPidFile(pidfile):
    """ mostly comes from _twistd_unix.py which is not twisted public API :-/

        except it returns an exception instead of exiting
    """
    if os.path.exists(pidfile):
        try:
            with open(pidfile) as f:
                pid = int(f.read())
        except ValueError:
            raise ValueError('Pidfile {} contains non-numeric value'.format(pidfile))
        try:
            os.kill(pid, 0)
        except OSError as why:
            if why.errno == errno.ESRCH:
                # The pid doesn't exist.
                print('Removing stale pidfile {}'.format(pidfile))
                os.remove(pidfile)
            else:
                raise OSError("Can't check status of PID {} from pidfile {}: {}".format(
                    pid, pidfile, why))
        else:
            raise BusyError("'{}' exists - is this master still running?".format(pidfile))
def checkPidFile ( pidfile ) : if os . path . exists ( pidfile ) : try : with open ( pidfile ) as f : pid = int ( f . read ( ) ) except ValueError : raise ValueError ( 'Pidfile {} contains non-numeric value' . format ( pidfile ) ) try : os . kill ( pid , 0 ) except OSError as why : if why . errno == errno . ESRCH : print ( 'Removing stale pidfile {}' . format ( pidfile ) ) os . remove ( pidfile ) else : raise OSError ( "Can't check status of PID {} from pidfile {}: {}" . format ( pid , pidfile , why ) ) else : raise BusyError ( "'{}' exists - is this master still running?" . format ( pidfile ) )
mostly comes from _twistd_unix.py which is not twisted public API :-/

        except it returns an exception instead of exiting