# HG changeset patch # User Marcin Kuzminski # Date 1285438676 -7200 # Node ID d280aa1c85c626f25d4b089a3791f1a0d313b02a # Parent 3d6d548ad3cc3415662edadb455b370170266bf0 removed pidlock from whoosh and added it as locked_task decorator diff -r 3d6d548ad3cc -r d280aa1c85c6 pylons_app/lib/celerylib/tasks.py --- a/pylons_app/lib/celerylib/tasks.py Fri Sep 24 18:13:29 2010 +0200 +++ b/pylons_app/lib/celerylib/tasks.py Sat Sep 25 20:17:56 2010 +0200 @@ -66,20 +66,11 @@ return settings @task +@locked_task def whoosh_index(repo_location, full_index): log = whoosh_index.get_logger() - from pylons_app.lib.pidlock import DaemonLock - from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon, LockHeld - try: - l = DaemonLock() - WhooshIndexingDaemon(repo_location=repo_location)\ - .run(full_index=full_index) - l.release() - return 'Done' - except LockHeld: - log.info('LockHeld') - return 'LockHeld' - + from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon + WhooshIndexingDaemon(repo_location=repo_location).run(full_index=full_index) @task @locked_task diff -r 3d6d548ad3cc -r d280aa1c85c6 pylons_app/lib/pidlock.py --- a/pylons_app/lib/pidlock.py Fri Sep 24 18:13:29 2010 +0200 +++ b/pylons_app/lib/pidlock.py Sat Sep 25 20:17:56 2010 +0200 @@ -9,7 +9,7 @@ """daemon locking USAGE: try: - l = lock() + l = DaemonLock(desc='test lock') main() l.release() except LockHeld: @@ -40,8 +40,7 @@ def lock(self): - """ - locking function, if lock is present it will raise LockHeld exception + """locking function, if lock is present it will raise LockHeld exception """ lockname = '%s' % (os.getpid()) @@ -75,8 +74,7 @@ def release(self): - """ - releases the pid by removing the pidfile + """releases the pid by removing the pidfile """ if self.callbackfn: #execute callback function on release @@ -105,23 +103,3 @@ pidfile.write(lockname) pidfile.close self.held = True - - -def main(): - print 'func is running' - cnt = 20 - while 1: - print cnt - if cnt == 0: - break - time.sleep(1) - cnt -= 1 - - -if __name__ == "__main__": - try: - l = DaemonLock(desc='test lock') - main() - l.release() - except LockHeld: - sys.exit(1)