[Piuparts-commits] [piuparts] 05/12: p-r: acquire a global "report.lock"

Holger Levsen holger at layer-acht.org
Wed Oct 11 14:58:44 UTC 2017


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit 4594e83cc8923409e17e7dc116d9238abd6d1c00
Author: Andreas Beckmann <anbe at debian.org>
Date:   Wed Oct 4 04:47:05 2017 +0200

    p-r: acquire a global "report.lock"
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
    Signed-off-by: Holger Levsen <holger at layer-acht.org>
---
 debian/changelog   | 2 ++
 piuparts-report.py | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 13def9e..9f84a35 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,8 @@ piuparts (0.83) UNRELEASED; urgency=medium
     - Use test_versions() in all places referring to a piuparts test.
     - Set test_versions while loading versions from the final target distro.
     - Use the actual package versions for resolving the "outdated" state.
+  * piuparts-report.py:
+    - Use global locks to allow only one running instance of each script.
 
  -- Holger Levsen <holger at debian.org>  Sat, 07 Oct 2017 17:42:12 +0200
 
diff --git a/piuparts-report.py b/piuparts-report.py
index 41ea235..bc0e98c 100644
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -37,6 +37,7 @@ import yaml
 import hashlib
 import pickle
 import random
+import fcntl
 from urllib2 import HTTPError, URLError
 
 # if python-rpy2 ain't installed, we don't draw fancy graphs
@@ -1778,7 +1779,12 @@ def main():
         os.makedirs(master_directory)
         return
 
-    if True:
+    with open(os.path.join(master_directory, "report.lock"), "we") as lock:
+        try:
+            fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except IOError:
+            sys.exit("another piuparts-report process is already running")
+
         packagedb_cache = {}
         create_file(os.path.join(output_directory, "sections.yaml"),
             yaml.dump(section_names, default_flow_style=False))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list