Package list mirage / 7920658
Add locks to fix thumbnail generating race condition (Closes: #7) Thomas Ross 1 year, 5 months ago
1 changed file(s) with 24 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
192192 self.thumbnail_sizes = ["128", "96", "72", "64", "48", "32"]
193193 self.thumbnail_size = 128 # Default to 128 x 128
194194 self.thumbnail_loaded = []
195 self.thumbpane_updating = False
195 self.thumbpane_stop_updating = {}
196 self.thumbpane_stop_updating_lock = threading.Lock()
197 self.thumbpane_update_lock = threading.Lock()
196198 self.recentfiles = ["", "", "", "", ""]
197199 self.screenshot_delay = 2
198200 self.thumbpane_bottom_coord_loaded = 0
742744 end_image = force_upto_imgnum
743745
744746 # update images:
747 with self.thumbpane_stop_updating_lock:
748 for thread_id in self.thumbpane_stop_updating:
749 self.thumbpane_stop_updating[thread_id] = True
750
745751 thread = threading.Thread(
746752 target=self.thumbpane_update_pending_images,
747753 args=(start_image, end_image, force_upto_imgnum),
765771 os.mkdir(os.path.expanduser("~/.thumbnails/normal/"))
766772
767773 def thumbpane_update_pending_images(self, start, end, select_image):
768 self.thumbpane_updating = True
774 thread_id = threading.get_ident()
775 with self.thumbpane_stop_updating_lock:
776 self.thumbpane_stop_updating[thread_id] = False
777
778 if not self.thumbpane_update_lock.acquire():
779 return
780
769781 self.thumbpane_create_dir()
770782 # Check to see if any images need their thumbnails generated.
771783 curr_coord = 0
772784 imgnum = 0
773785
774786 for imgnum in range(start, end + 1):
775 if self.closing_app or self.stop_now or not self.thumbpane_show:
787 if (
788 self.thumbpane_stop_updating.get(thread_id)
789 or self.closing_app
790 or self.stop_now
791 or not self.thumbpane_show
792 ):
776793 break
777794
778795 if imgnum >= len(self.image_list):
783800 if select_image == imgnum and select_image == self.curr_img_in_list:
784801 GLib.idle_add(self.thumbpane_select, select_image)
785802
786 self.thumbpane_updating = False
803 with self.thumbpane_stop_updating_lock:
804 del self.thumbpane_stop_updating[thread_id]
805
806 self.thumbpane_update_lock.release()
787807
788808 def thumbpane_clear_list(self):
789809 self.thumbpane_bottom_coord_loaded = 0