forked from github/server
Diverse Bugfixes
This commit is contained in:
parent
24f3cbd6ae
commit
538bed3c70
|
@ -6,14 +6,12 @@ import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import locking
|
import locking
|
||||||
from locking import trylock, unlock
|
from locking import lock, unlock
|
||||||
|
|
||||||
From="accounts@vinyambar.de"
|
From="accounts@vinyambar.de"
|
||||||
|
|
||||||
# lock the input file:
|
# lock the input file:
|
||||||
if (trylock(sys.argv[1]+'.err')!=0):
|
lock(sys.argv[1]+'.err',180)
|
||||||
print "Could not lock "+sys.argv[1]+".err"
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# move input file then unlock it:
|
# move input file then unlock it:
|
||||||
if os.access(sys.argv[1]+'.err', os.F_OK)==0:
|
if os.access(sys.argv[1]+'.err', os.F_OK)==0:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ def trylock(file):
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def lock(file):
|
def lock(file, timeout=60):
|
||||||
locked=1
|
locked=1
|
||||||
while locked:
|
while locked:
|
||||||
try:
|
try:
|
||||||
|
@ -19,7 +20,7 @@ def lock(file):
|
||||||
except:
|
except:
|
||||||
update=os.stat(file+'.lock')[stat.ST_MTIME]
|
update=os.stat(file+'.lock')[stat.ST_MTIME]
|
||||||
now=time.time()
|
now=time.time()
|
||||||
if (now > update + 60):
|
if (now > update + timeout):
|
||||||
locked=0
|
locked=0
|
||||||
print "removing stale lockfile "+file+".lock"
|
print "removing stale lockfile "+file+".lock"
|
||||||
os.unlink(file+'.lock')
|
os.unlink(file+'.lock')
|
||||||
|
|
Loading…
Reference in New Issue