Show More
@@ -66,20 +66,11 def get_hg_ui_settings(): | |||
|
66 | 66 | return settings |
|
67 | 67 | |
|
68 | 68 | @task |
|
69 | @locked_task | |
|
69 | 70 | def whoosh_index(repo_location, full_index): |
|
70 | 71 | log = whoosh_index.get_logger() |
|
71 |
from pylons_app.lib. |
|
|
72 | from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon, LockHeld | |
|
73 | try: | |
|
74 | l = DaemonLock() | |
|
75 | WhooshIndexingDaemon(repo_location=repo_location)\ | |
|
76 | .run(full_index=full_index) | |
|
77 | l.release() | |
|
78 | return 'Done' | |
|
79 | except LockHeld: | |
|
80 | log.info('LockHeld') | |
|
81 | return 'LockHeld' | |
|
82 | ||
|
72 | from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon | |
|
73 | WhooshIndexingDaemon(repo_location=repo_location).run(full_index=full_index) | |
|
83 | 74 | |
|
84 | 75 | @task |
|
85 | 76 | @locked_task |
@@ -9,7 +9,7 class DaemonLock(object): | |||
|
9 | 9 | """daemon locking |
|
10 | 10 | USAGE: |
|
11 | 11 | try: |
|
12 | l = lock() | |
|
12 | l = DaemonLock(desc='test lock') | |
|
13 | 13 | main() |
|
14 | 14 | l.release() |
|
15 | 15 | except LockHeld: |
@@ -40,8 +40,7 class DaemonLock(object): | |||
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | def lock(self): |
|
43 | """ | |
|
44 | locking function, if lock is present it will raise LockHeld exception | |
|
43 | """locking function, if lock is present it will raise LockHeld exception | |
|
45 | 44 | """ |
|
46 | 45 | lockname = '%s' % (os.getpid()) |
|
47 | 46 | |
@@ -75,8 +74,7 class DaemonLock(object): | |||
|
75 | 74 | |
|
76 | 75 | |
|
77 | 76 | def release(self): |
|
78 | """ | |
|
79 | releases the pid by removing the pidfile | |
|
77 | """releases the pid by removing the pidfile | |
|
80 | 78 | """ |
|
81 | 79 | if self.callbackfn: |
|
82 | 80 | #execute callback function on release |
@@ -105,23 +103,3 class DaemonLock(object): | |||
|
105 | 103 | pidfile.write(lockname) |
|
106 | 104 | pidfile.close |
|
107 | 105 | self.held = True |
|
108 | ||
|
109 | ||
|
110 | def main(): | |
|
111 | print 'func is running' | |
|
112 | cnt = 20 | |
|
113 | while 1: | |
|
114 | print cnt | |
|
115 | if cnt == 0: | |
|
116 | break | |
|
117 | time.sleep(1) | |
|
118 | cnt -= 1 | |
|
119 | ||
|
120 | ||
|
121 | if __name__ == "__main__": | |
|
122 | try: | |
|
123 | l = DaemonLock(desc='test lock') | |
|
124 | main() | |
|
125 | l.release() | |
|
126 | except LockHeld: | |
|
127 | sys.exit(1) |
General Comments 0
You need to be logged in to leave comments.
Login now