def write_pid_file ( ) : pidfile = os . path . basename ( sys . argv [ 0 ] ) [ : - 3 ] + '.pid' # strip .py, add .pid with open ( pidfile , 'w' ) as fh : fh . write ( "%d\n" % os . getpid ( ) ) fh . close ( )
outputting pid to file linux python
Write a file with the PID of this server instance .
def write_pid_file():
    """Write a file with the PID of this server instance.

    Call when setting up a command line testserver.
    """
    pidfile = os.path.basename(sys.argv[0])[:-3] + '.pid'  # strip .py, add .pid
    with open(pidfile, 'w') as fh:
        fh.write("%d\n" % os.getpid())
        fh.close()