From 938e7e04c2672a9577330b657061cd956e4b1119 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Fri, 5 Jan 2007 11:20:50 +0000 Subject: [PATCH] Avoid concurrent access to the datorhandbok server. --- check_datorhandbok | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/check_datorhandbok b/check_datorhandbok index 315415e..a1007dd 100755 --- a/check_datorhandbok +++ b/check_datorhandbok @@ -3,6 +3,7 @@ import re import urllib2 +import fcntl import BeautifulSoup @@ -58,7 +59,16 @@ def check_host(hostname): ok(hostname, "all ok") +def check_host_locked(hostname): + f = open("/tmp/datorhandok.lck", "a") + try: + fcntl.flock(f, fcntl.LOCK_EX) + check_host(hostname) + finally: + fcntl.flock(f, fcntl.LOCK_UN) + f.close() + if __name__ == '__main__': import sys - check_host(sys.argv[1]) + check_host_locked(sys.argv[1]) -- GitLab