[Blends-commit] r2983 - in /blends/trunk/webtools: blendstasktools.py tasks.py
tille at users.alioth.debian.org
tille at users.alioth.debian.org
Thu Oct 20 11:05:49 UTC 2011
Author: tille
Date: Thu Oct 20 11:05:49 2011
New Revision: 2983
URL: http://svn.debian.org/wsvn/blends/?sc=1&rev=2983
Log:
Implement locking to make sure that not more than one instance is running. This became necessary since udd.debian.net has serious IO performance problems and jobs do not end properly in a reasonable time frame.
Modified:
blends/trunk/webtools/blendstasktools.py
blends/trunk/webtools/tasks.py
Modified: blends/trunk/webtools/blendstasktools.py
URL: http://svn.debian.org/wsvn/blends/blends/trunk/webtools/blendstasktools.py?rev=2983&op=diff
==============================================================================
--- blends/trunk/webtools/blendstasktools.py (original)
+++ blends/trunk/webtools/blendstasktools.py Thu Oct 20 11:05:49 2011
@@ -204,6 +204,35 @@
'contrib' : 'DFSG free, but needs non-free components',
'non-free' : 'non-free'
}
+
+import psutil
+
+LOCKFILE='/var/lock/blends.lock'
+def LockBlendsTools():
+ """Locking mechanism to make sure the scripts will not run in parallel
+ which happened because of IO problems on udd.debian.org"""
+ if os.path.exists(LOCKFILE):
+ try:
+ lf = open(LOCKFILE, 'r')
+ pid = int(lf.readline())
+ lf.close()
+ if pid in psutil.get_pid_list():
+ print >>stderr, "Another process rebuilding web sentinal pages with PID %i is running. Exit." % pid
+ exit()
+ else:
+ print >>stderr, "Warning: Process with PID %i is not running any more but lockfile remained. Removing %s ..." % (pid, LOCKFILE)
+ os.unlink(LOCKFILE)
+ except IOError as e:
+ pass
+ pid = os.getpid()
+ lf = open(LOCKFILE, 'w')
+ print >>lf, pid
+ lf.close()
+
+def UnlockBlendsTools():
+ """Unlock previousely locked file"""
+ if os.path.exists(LOCKFILE):
+ os.unlink(LOCKFILE)
def GetDependencies2Use(dependencystatus=[], max_order='prospective'):
# Create a list of status of dependencies out of pkgstatus dictionary
Modified: blends/trunk/webtools/tasks.py
URL: http://svn.debian.org/wsvn/blends/blends/trunk/webtools/tasks.py?rev=2983&op=diff
==============================================================================
--- blends/trunk/webtools/tasks.py (original)
+++ blends/trunk/webtools/tasks.py Thu Oct 20 11:05:49 2011
@@ -17,7 +17,7 @@
from genshi import Markup
from genshi.template.eval import UndefinedError
-from blendstasktools import Tasks, GetDependencies2Use, pkgstatus, pkgstatus_sortedkeys
+from blendstasktools import Tasks, GetDependencies2Use, pkgstatus, pkgstatus_sortedkeys, LockBlendsTools, UnlockBlendsTools
from blendsunicode import to_unicode
from blendslanguages import languages, language_dict
@@ -26,6 +26,7 @@
% argv[0]
exit(-1)
+LockBlendsTools()
tasks = Tasks(argv[1])
tasks.GetAllDependencies()
packages = tasks.GetNamesOnlyDict()
@@ -294,3 +295,5 @@
print >> htafp
htafp.close()
+
+UnlockBlendsTools()
More information about the Blends-commit
mailing list