test read seraile iniziale
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import fcntl
|
||||
import os
|
||||
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# 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'
|
||||
logga ( "LOCK: Piu istanze aperte")
|
||||
sys.exit ( 0 )
|
||||
|
||||
#- print '\n running alone ...\n'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user