Changeset 2883 for pykota/trunk
- Timestamp:
- 05/11/06 16:08:45 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2882 r2883 27 27 import sys 28 28 import os 29 import fcntl 29 30 import time 30 31 import errno … … 113 114 self.logdebug("SIGINT enabled.") 114 115 116 def waitForLock(self) : 117 """Waits until we can acquire the lock file.""" 118 self.logdebug("Waiting for lock...") 119 stillrunning = True 120 while 1 : 121 self.lockfile = open(self.lockfilename, "a+") 122 fcntl.lockf(self.lockfile, fcntl.LOCK_EX) # Will wait until lock available 123 self.lockfile.seek(0, 0) 124 try : 125 oldpid = int(self.lockfile.read().strip()) 126 except : 127 stillrunning = False 128 else : 129 try : 130 os.kill(oldpid, 0) 131 except OSError : 132 stillrunning = False 133 if not stillrunning : 134 self.lockfile.seek(0, 0) 135 self.lockfile.write("%i" % self.pid) 136 self.lockfile.flush() 137 break 138 else : 139 time.sleep(0.1) 140 self.logdebug("Lock acquired.") 141 115 142 def discoverOtherBackends(self) : 116 143 """Discovers the other CUPS backends. … … 257 284 (jbtype, self.JobBillingCode) = jbing 258 285 286 self.lockfilename = os.path.join(self.Directory, "%s-%s..LCK" % (self.myname, self.PrinterName)) 287 259 288 self.logdebug("Backend : %s" % self.RealBackend) 260 289 self.logdebug("DeviceURI : %s" % self.DeviceURI) … … 404 433 self.logdebug("Work file %s will be kept." % self.DataFile) 405 434 PyKotaTool.clean(self) 435 self.logdebug("Removing lock...") 436 try : 437 fcntl.flock(self.lockfile, fcntl.LOCK_UN) 438 self.lockfile.close() 439 # NB : we don't remove the lock file, since it might already be opened by another process. 440 except : 441 pass 442 else : 443 self.logdebug("Lock removed.") 406 444 self.logdebug("Clean.") 407 445 … … 1251 1289 wrapper.deferredInit() 1252 1290 wrapper.initBackendParameters() 1291 wrapper.waitForLock() 1253 1292 wrapper.saveDatasAndCheckSum() 1254 1293 wrapper.preaccounter = openAccounter(wrapper, ispreaccounter=1) -
pykota/trunk/NEWS
r2882 r2883 24 24 - 1.25alpha3 (2006-05-11) : 25 25 26 - Added a lock to ensure that a single cupspykota backend 27 is processing datas for a particular print queue at any 28 given time. 29 26 30 - Now exports more environment variables for the subprocesses. 27 31