def kill_old_process():
 pidfile = PidFile('agent-manager-gui').get_path()
 old_pid = None
 try:
  pf = file(pidfile, 'r')
  old_pid = int(pf.read().strip())
  pf.close()
 except (IOError, ValueError):
  pass
 if (old_pid is not None):
  try:
   p = psutil.Process(old_pid)
   if ('agent-manager.exe' in p.name()):
    p.terminate()
  except (psutil.NoSuchProcess, psutil.AccessDenied):
   pass
 pid = str(os.getpid())
 try:
  with open(pidfile, 'w+') as fp:
   fp.write(str(pid))
 except Exception as e:
  msg = ('Unable to write pidfile: %s %s' % (pidfile, str(e)))
  log.exception(msg)
  sys.stderr.write((msg + '\n'))
  sys.exit(1)

def kill_old_process ( ) : pidfile = PidFile ( 'agent-manager-gui' ) . get_path ( ) old_pid = None try : pf = file ( pidfile , 'r' ) old_pid = int ( pf . read ( ) . strip ( ) ) pf . close ( ) except ( IOError , ValueError ) : pass if ( old_pid is not None ) : try : p = psutil . Process ( old_pid ) if ( 'agent-manager.exe' in p . name ( ) ) : p . terminate ( ) except ( psutil . NoSuchProcess , psutil . AccessDenied ) : pass pid = str ( os . getpid ( ) ) try : with open ( pidfile , 'w+' ) as fp : fp . write ( str ( pid ) ) except Exception as e : msg = ( 'Unable to write pidfile: %s %s' % ( pidfile , str ( e ) ) ) log . exception ( msg ) sys . stderr . write ( ( msg + '\n' ) ) sys . exit ( 1 )
kills any other instance of this program .