def acquire_for(pid_dir, num_available=1, kill_signal=None):
 (my_pid, my_cmd, pid_file) = get_info(pid_dir)
 if (not os.path.exists(pid_dir)):
  os.mkdir(pid_dir)
  os.chmod(pid_dir, 511)
 pids = {pid for pid in _read_pids_file(pid_file) if (getpcmd(pid) == my_cmd)}
 if (kill_signal is not None):
  for pid in pids:
   os.kill(pid, kill_signal)
  print('Sent kill signal to Pids: {}'.format(pids))
  num_available += 1
 if (len(pids) >= num_available):
  print('Pid(s) {} already running'.format(pids))
  if (kill_signal is not None):
   print('Note: There have (probably) been 1 other "--take-lock" process which continued to run! Probably no need to run this one as well.')
  return False
 _write_pids_file(pid_file, (pids | {my_pid}))
 return True

def acquire_for ( pid_dir , num_available = 1 , kill_signal = None ) : ( my_pid , my_cmd , pid_file ) = get_info ( pid_dir ) if ( not os . path . exists ( pid_dir ) ) : os . mkdir ( pid_dir ) os . chmod ( pid_dir , 511 ) pids = { pid for pid in _read_pids_file ( pid_file ) if ( getpcmd ( pid ) == my_cmd ) } if ( kill_signal is not None ) : for pid in pids : os . kill ( pid , kill_signal ) print ( 'Sent kill signal to Pids: {}' . format ( pids ) ) num_available += 1 if ( len ( pids ) >= num_available ) : print ( 'Pid(s) {} already running' . format ( pids ) ) if ( kill_signal is not None ) : print ( 'Note: There have (probably) been 1 other "--take-lock" process which continued to run! Probably no need to run this one as well.' ) return False _write_pids_file ( pid_file , ( pids | { my_pid } ) ) return True
makes sure the process is only run once at the same time with the same name .