#NEWLINE# def stop( self ) : #NEWLINE# #INDENT# 'Stop the daemon.' #NEWLINE# pid = None #NEWLINE# if os . path . exists ( self . pidfile ) : #NEWLINE# #INDENT# with open ( self . pidfile , 'r' ) as fp : #NEWLINE# #INDENT# pid = int ( fp . read ( ) . strip ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not pid ) : #NEWLINE# #INDENT# msg = 'pidfile (%s) does not exist. Daemon not running?\n' #NEWLINE# sys . stderr . write ( ( msg % self . pidfile ) ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# while 1 : #NEWLINE# #INDENT# os . kill ( pid , SIGTERM ) #NEWLINE# time . sleep ( 0.1 ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# e = str ( e ) #NEWLINE# if ( e . find ( 'No such process' ) > 0 ) : #NEWLINE# #INDENT# if os . path . exists ( self . pidfile ) : #NEWLINE# #INDENT# os . remove ( self . pidfile ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( e ) #NEWLINE# sys . exit ( 1 )