import fcntl import os import logging #--------------------------------------------------------------- # meccanismo di file lock per evitare multiple instances # The function will try to lock the file specified , if it success, return True, else return False. # The nice thing is that the lock will be dropped when the program terminates. # >>>Use : # if not lockFile(".lock.pod"): # sys.exit(0) def lockFile ( lockfile ) : fd = os.open ( lockfile , os.O_CREAT | os.O_TRUNC | os.O_WRONLY ) try: # Request exclusive (EX) non-blocking (NB) advisory lock. fcntl.lockf ( fd , fcntl.LOCK_EX | fcntl.LOCK_NB ) except IOError: return False return True if not lockFile ( ".lockfile" ) : print '\n noi non siamo soli ...\n' logging.error( "LOCK: Piu istanze aperte") #sys.exit ( 0 ) #- print '\n running alone ...\n'