139 |
139 |
140 self.borg_instance.wait() |
140 self.borg_instance.wait() |
141 |
141 |
142 logging.debug('Borg subprocess terminated; terminating log listener thread') |
142 logging.debug('Borg subprocess terminated; terminating log listener thread') |
143 |
143 |
144 with self.lock: |
|
145 self.thread_log=None |
|
146 self.__finish_and_reschedule_if_both_listeners_terminated() |
|
147 |
|
148 |
|
149 def __result_listener(self): |
144 def __result_listener(self): |
150 with self.lock: |
145 with self.lock: |
151 status, callback=self.__status_unlocked() |
146 status, callback=self.__status_unlocked() |
152 if callback: |
147 if callback: |
153 callback(self, status) |
148 callback(self, status) |
166 logging.debug('Waiting for borg subprocess to terminate in result thread') |
161 logging.debug('Waiting for borg subprocess to terminate in result thread') |
167 |
162 |
168 success=success and self.borg_instance.wait() |
163 success=success and self.borg_instance.wait() |
169 |
164 |
170 logging.debug('Borg subprocess terminated (success: %s); terminating result listener thread' % str(success)) |
165 logging.debug('Borg subprocess terminated (success: %s); terminating result listener thread' % str(success)) |
|
166 |
|
167 self.thread_log.join() |
171 |
168 |
172 with self.lock: |
169 with self.lock: |
173 if self.current_operation['operation']=='create': |
170 if self.current_operation['operation']=='create': |
174 self.lastrun=self.current_operation['when_monotonic'] |
171 self.lastrun=self.current_operation['when_monotonic'] |
175 self.lastrun_success=success |
172 self.lastrun_success=success |
176 self.thread_res=None |
173 self.thread_res=None |
177 self.__finish_and_reschedule_if_both_listeners_terminated() |
174 self.thread_log=None |
|
175 self.borg_instance=None |
|
176 self.current_operation=None |
|
177 self.__schedule_unlocked() |
178 status, callback=self.__status_unlocked() |
178 status, callback=self.__status_unlocked() |
179 if callback: |
179 if callback: |
180 callback(self, status) |
180 callback(self, status) |
181 |
|
182 def __finish_and_reschedule_if_both_listeners_terminated(self): |
|
183 if self.thread_res==None and self.thread_log==None: |
|
184 logging.debug('Both threads terminated') |
|
185 self.borg_instance=None |
|
186 self.current_operation=None |
|
187 self.__schedule_unlocked() |
|
188 |
181 |
189 def __do_launch(self, queue, op, archive_or_repository, *args): |
182 def __do_launch(self, queue, op, archive_or_repository, *args): |
190 inst=BorgInstance(op['operation'], archive_or_repository, *args) |
183 inst=BorgInstance(op['operation'], archive_or_repository, *args) |
191 inst.launch() |
184 inst.launch() |
192 |
185 |