Show More
@@ -66,20 +66,11 def get_hg_ui_settings(): | |||||
66 | return settings |
|
66 | return settings | |
67 |
|
67 | |||
68 | @task |
|
68 | @task | |
|
69 | @locked_task | |||
69 | def whoosh_index(repo_location, full_index): |
|
70 | def whoosh_index(repo_location, full_index): | |
70 | log = whoosh_index.get_logger() |
|
71 | log = whoosh_index.get_logger() | |
71 |
from pylons_app.lib. |
|
72 | from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon | |
72 | from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon, LockHeld |
|
73 | WhooshIndexingDaemon(repo_location=repo_location).run(full_index=full_index) | |
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 |
|
||||
83 |
|
74 | |||
84 | @task |
|
75 | @task | |
85 | @locked_task |
|
76 | @locked_task |
@@ -9,7 +9,7 class DaemonLock(object): | |||||
9 | """daemon locking |
|
9 | """daemon locking | |
10 | USAGE: |
|
10 | USAGE: | |
11 | try: |
|
11 | try: | |
12 | l = lock() |
|
12 | l = DaemonLock(desc='test lock') | |
13 | main() |
|
13 | main() | |
14 | l.release() |
|
14 | l.release() | |
15 | except LockHeld: |
|
15 | except LockHeld: | |
@@ -40,8 +40,7 class DaemonLock(object): | |||||
40 |
|
40 | |||
41 |
|
41 | |||
42 | def lock(self): |
|
42 | def lock(self): | |
43 | """ |
|
43 | """locking function, if lock is present it will raise LockHeld exception | |
44 | locking function, if lock is present it will raise LockHeld exception |
|
|||
45 | """ |
|
44 | """ | |
46 | lockname = '%s' % (os.getpid()) |
|
45 | lockname = '%s' % (os.getpid()) | |
47 |
|
46 | |||
@@ -75,8 +74,7 class DaemonLock(object): | |||||
75 |
|
74 | |||
76 |
|
75 | |||
77 | def release(self): |
|
76 | def release(self): | |
78 | """ |
|
77 | """releases the pid by removing the pidfile | |
79 | releases the pid by removing the pidfile |
|
|||
80 | """ |
|
78 | """ | |
81 | if self.callbackfn: |
|
79 | if self.callbackfn: | |
82 | #execute callback function on release |
|
80 | #execute callback function on release | |
@@ -105,23 +103,3 class DaemonLock(object): | |||||
105 | pidfile.write(lockname) |
|
103 | pidfile.write(lockname) | |
106 | pidfile.close |
|
104 | pidfile.close | |
107 | self.held = True |
|
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