@@ -176,13 +176,17 @@ def _build_snapshot(self, config: WatchConfig) -> Dict[str, Tuple[int, int, int]
176176 continue
177177 return snap
178178
179- def _scanner_loop (self , watch_id : str ) -> None :
179+ def _scanner_loop (
180+ self ,
181+ watch_id : str ,
182+ initial_snapshot : Optional [Dict [str , Tuple [int , int , int ]]] = None ,
183+ ) -> None :
180184 config = WatchConfig .from_dict (self .watches [watch_id ]["config" ])
181185 root = Path (config .folder_path ).expanduser ().resolve ()
182186 queue = self .queues [watch_id ]
183187 evt = self .running [watch_id ]
184188
185- prev = self ._build_snapshot (config )
189+ prev = dict ( initial_snapshot or self ._build_snapshot (config ) )
186190 while evt .is_set ():
187191 current = self ._build_snapshot (config )
188192
@@ -349,8 +353,13 @@ def start_watch(self, config: WatchConfig) -> str:
349353 self .queues [watch_id ] = Queue ()
350354 self .running [watch_id ] = threading .Event ()
351355 self .running [watch_id ].set ()
356+ initial_snapshot = self ._build_snapshot (config )
352357
353- s = threading .Thread (target = self ._scanner_loop , args = (watch_id ,), daemon = True )
358+ s = threading .Thread (
359+ target = self ._scanner_loop ,
360+ args = (watch_id , initial_snapshot ),
361+ daemon = True ,
362+ )
354363 w = threading .Thread (target = self ._worker_loop , args = (watch_id ,), daemon = True )
355364 s .start ()
356365 w .start ()
0 commit comments