index_cache_thread.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import threading
34 import time
35 
36 
37 class IndexCacheThread(threading.Thread):
38 
39  """
40  Updates invalid caches.
41  One thread per timeline.
42  """
43 
44  def __init__(self, timeline):
45  threading.Thread.__init__(self)
46  self.timeline = timeline
47  self._stop_flag = False
48  self.setDaemon(True)
49  self.start()
50 
51  def run(self):
52  while not self._stop_flag:
53  with self.timeline.index_cache_cv:
54  # Wait until the cache is dirty
55  while len(self.timeline.invalidated_caches) == 0:
56  self.timeline.index_cache_cv.wait()
57  if self._stop_flag:
58  return
59  # Update the index for one topic
60  total_topics = len(self.timeline.topics)
61  update_step = max(1, total_topics / 100)
62  topic_num = 1
63  progress = 0
64  updated = False
65  for topic in self.timeline.topics:
66  if topic in self.timeline.invalidated_caches:
67  updated = (self.timeline._update_index_cache(topic) > 0)
68  if topic_num % update_step == 0 or topic_num == total_topics:
69  new_progress = int(100.0 * (float(topic_num) / total_topics))
70  if new_progress != progress:
71  progress = new_progress
72  if not self._stop_flag:
73  self.timeline.scene().background_progress = progress
74  self.timeline.scene().status_bar_changed_signal.emit()
75  topic_num += 1
76 
77  if updated:
78  self.timeline.scene().background_progress = 0
79  self.timeline.scene().status_bar_changed_signal.emit()
80  self.timeline.scene().update()
81  # Give the GUI some time to update
82  time.sleep(1.0)
83 
84  def stop(self):
85  self._stop_flag = True
86  cv = self.timeline.index_cache_cv
87  with cv:
88  cv.notify()


rqt_bag
Author(s): Aaron Blasdel, Tim Field
autogenerated on Fri Jun 7 2019 22:05:54