def __grab_lock():
 try:
  if LOCK_ENABLED:
   if (not os.path.exists('/var/lib/cobbler/lock')):
    fd = open('/var/lib/cobbler/lock', 'w+')
    fd.close()
   LOCK_HANDLE = open('/var/lib/cobbler/lock', 'r')
   fcntl.flock(LOCK_HANDLE.fileno(), fcntl.LOCK_EX)
 except:
  traceback.print_exc()
  sys.exit(7)

def __grab_lock ( ) : try : if LOCK_ENABLED : if ( not os . path . exists ( '/var/lib/cobbler/lock' ) ) : fd = open ( '/var/lib/cobbler/lock' , 'w+' ) fd . close ( ) LOCK_HANDLE = open ( '/var/lib/cobbler/lock' , 'r' ) fcntl . flock ( LOCK_HANDLE . fileno ( ) , fcntl . LOCK_EX ) except : traceback . print_exc ( ) sys . exit ( 7 )
dual purpose locking: (a) flock to avoid multiple process access (b) block signal handler to avoid ctrl+c while writing yaml .