Download:
child 83:ad889ea48249
parent 81:51c58566e6bd
82:5a8a919160a5
Anton Shestakov <av6@dwimlabs.net>, Sun, 07 Aug 2016 12:59:40 +0800
bench: write pid into lockfile, properly close it

1 файлов изменено, 15 вставок(+), 7 удалений(-) [+]
bench.py file | annotate | diff | comparison | revisions
--- a/bench.py Fri Aug 05 12:27:07 2016 +0800
+++ b/bench.py Sun Aug 07 12:59:40 2016 +0800
@@ -265,10 +265,11 @@
conn.close()
-def lock():
- flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
+def lock(path):
try:
- return os.fdopen(os.open(LOCKFILE, flags), 'w')
+ fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
+ os.write(fd, '%d' % os.getpid())
+ return fd
except OSError as e:
if e.errno == errno.EEXIST:
logging.error('cannot lock data directory')
@@ -277,8 +278,15 @@
raise
-def unlock():
- os.remove(LOCKFILE)
+def unlock(fd, path):
+ try:
+ os.close(fd)
+ os.remove(path)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ logging.info("lock file %r doesn't exist", path)
+ else:
+ raise
def main(args):
@@ -287,7 +295,7 @@
else:
names = args.marks.split(',')
marks = OrderedDict((k, v) for k, v in MARKS.items() if k in names)
- lock()
+ lockfd = lock(LOCKFILE)
try:
dbinit()
if args.auto:
@@ -297,7 +305,7 @@
args.revsets = guessnew(args.auto, marks)
dbupdate(args.revsets, marks, args.mintime, args.mintries, args.retry)
finally:
- unlock()
+ unlock(lockfd, LOCKFILE)
if __name__ == '__main__':