You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by aj...@apache.org on 2005/03/09 14:43:02 UTC
svn commit: r156641 - in gump/trunk/python/gump: core/model/module.py
core/runner/demand.py util/locks.py
Author: ajack
Date: Wed Mar 9 05:42:57 2005
New Revision: 156641
URL: http://svn.apache.org/viewcvs?view=rev&rev=156641
Log:
Attempt to allow sharing of the SCM staging directory (on posix only) accross multiple (possibly concurrant) Gump processes.
Locks a file before attempting to update a module. Blocks waiting for the lock.
Modified:
gump/trunk/python/gump/core/model/module.py
gump/trunk/python/gump/core/runner/demand.py
gump/trunk/python/gump/util/locks.py
Modified: gump/trunk/python/gump/core/model/module.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/model/module.py?view=diff&r1=156640&r2=156641
==============================================================================
--- gump/trunk/python/gump/core/model/module.py (original)
+++ gump/trunk/python/gump/core/model/module.py Wed Mar 9 05:42:57 2005
@@ -403,10 +403,15 @@
os.path.join(workspace.getBaseDirectory(),
self.workdir))
- self.absSrcCtlDir= \
+ self.absSrcCtlDir= \
os.path.abspath(
- os.path.join( workspace.getSourceControlStagingDirectory(),
+ os.path.join( workspace.getSourceControlStagingDirectory(),
self.getName())) # todo allow override
+
+ # For when multiple gump runs share (on posix)
+ self.absUpdateLock= \
+ os.path.abspath(
+ os.path.join( self.absSrcCtlDir, 'update.lock'))
# :TODO: Consolidate this code, less cut-n-paste but also
# check the 'type' of the repository is appropriate for the
@@ -674,6 +679,9 @@
def getSourceControlStagingDirectory(self):
return self.absSrcCtlDir
+
+ def getUpdateLockFile(self):
+ return self.absUpdateLock
def getWorkingDirectory(self):
return self.absWorkingDir
Modified: gump/trunk/python/gump/core/runner/demand.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/runner/demand.py?view=diff&r1=156640&r2=156641
==============================================================================
--- gump/trunk/python/gump/core/runner/demand.py (original)
+++ gump/trunk/python/gump/core/runner/demand.py Wed Mar 9 05:42:57 2005
@@ -79,26 +79,38 @@
is delegated to the updater that's provided by the parent GumpRunner
class.
"""
-
- lock=module.getLock()
+ flock=None
try:
- lock.acquire()
+ # Only on POSIX can we block on a file lock,
+ # so only here do we support shared update
+ # staging areas.
+ if 'posix'==os.name:
+ flock = acquireLock(module.getUpdateLockFile())
+
+ # Normal thread locking...
+ lock=module.getLock()
+ try:
+ lock.acquire()
- if not module.isUpdated():
+ if not module.isUpdated():
- # Perform Update
- self.updater.updateModule(module)
+ # Perform Update
+ self.updater.updateModule(module)
- # Fire event
- self.run.generateEvent(module)
+ # Fire event
+ self.run.generateEvent(module)
- # Mark as done in set
- self.run.gumpSet.setCompletedModule(module)
+ # Mark as done in set
+ self.run.gumpSet.setCompletedModule(module)
- # Mark Updated
- module.setUpdated(True)
+ # Mark Updated
+ module.setUpdated(True)
+ finally:
+ lock.release()
finally:
- lock.release()
+ if flock:
+ releaseLock(flock,module.getUpdateLockFile())
+
def performBuild(self,project):
"""
Modified: gump/trunk/python/gump/util/locks.py
URL: http://svn.apache.org/viewcvs/gump/trunk/python/gump/util/locks.py?view=diff&r1=156640&r2=156641
==============================================================================
--- gump/trunk/python/gump/util/locks.py (original)
+++ gump/trunk/python/gump/util/locks.py Wed Mar 9 05:42:57 2005
@@ -22,35 +22,27 @@
#-----------------------------------------------------------------------#
-def establishLock(lockFile):
-
+def acquireLock(lockFile):
+ """ Block to ge an exclusive lock on a file. """
failed=0
- info=''
if 'posix'==os.name:
import fcntl
try:
lock=open(lockFile,'a+')
- fcntl.flock(lock.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
+ fcntl.flock(lock.fileno(), fcntl.LOCK_EX)
except:
failed=1
- info=', and is locked.'
-
else:
if os.path.exists(lockFile):
failed=1
-
- # Write this PID into a lock file
lock=open(lockFile,'w')
if failed:
- print """The lock file [%s] exists%s.
-Either Gump is still running, or it terminated very abnormally.
-Please resolve this (waiting or removing the lock file) before retrying.
- """ % (lockFile, info)
- sys.exit(1)
+ raise RuntimeError, \
+ """The lock file [%s] exists, and a lock could not be established.""" % lockFile
- # Leave a mark...
+ # Write this PID into a lock file
lock.write(`os.getpid()`)
lock.flush()
@@ -75,4 +67,5 @@
os.remove(lockFile)
except:
# Somehow another could delete this, even if locked...
+ # Or, could be in the process of locking it.
pass