diff --git a/mirage/__init__.py b/mirage/__init__.py index e920aae..13700cf 100755 --- a/mirage/__init__.py +++ b/mirage/__init__.py @@ -193,7 +193,9 @@ self.thumbnail_sizes = ["128", "96", "72", "64", "48", "32"] self.thumbnail_size = 128 # Default to 128 x 128 self.thumbnail_loaded = [] - self.thumbpane_updating = False + self.thumbpane_stop_updating = {} + self.thumbpane_stop_updating_lock = threading.Lock() + self.thumbpane_update_lock = threading.Lock() self.recentfiles = ["", "", "", "", ""] self.screenshot_delay = 2 self.thumbpane_bottom_coord_loaded = 0 @@ -743,6 +745,10 @@ end_image = force_upto_imgnum # update images: + with self.thumbpane_stop_updating_lock: + for thread_id in self.thumbpane_stop_updating: + self.thumbpane_stop_updating[thread_id] = True + thread = threading.Thread( target=self.thumbpane_update_pending_images, args=(start_image, end_image, force_upto_imgnum), @@ -766,14 +772,25 @@ os.mkdir(os.path.expanduser("~/.thumbnails/normal/")) def thumbpane_update_pending_images(self, start, end, select_image): - self.thumbpane_updating = True + thread_id = threading.get_ident() + with self.thumbpane_stop_updating_lock: + self.thumbpane_stop_updating[thread_id] = False + + if not self.thumbpane_update_lock.acquire(): + return + self.thumbpane_create_dir() # Check to see if any images need their thumbnails generated. curr_coord = 0 imgnum = 0 for imgnum in range(start, end + 1): - if self.closing_app or self.stop_now or not self.thumbpane_show: + if ( + self.thumbpane_stop_updating.get(thread_id) + or self.closing_app + or self.stop_now + or not self.thumbpane_show + ): break if imgnum >= len(self.image_list): @@ -784,7 +801,10 @@ if select_image == imgnum and select_image == self.curr_img_in_list: GLib.idle_add(self.thumbpane_select, select_image) - self.thumbpane_updating = False + with self.thumbpane_stop_updating_lock: + del self.thumbpane_stop_updating[thread_id] + + self.thumbpane_update_lock.release() def thumbpane_clear_list(self): self.thumbpane_bottom_coord_loaded = 0