L i2UdZddlmZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZdd lmZdd lmZe rdd lmZeeZd ed <dZd ed<dZd ed<GddZy)z.A class that watches a given path via polling.) annotationsN)ThreadPoolExecutor)Path) TYPE_CHECKINGFinal)StreamlitMaxRetriesError) get_loggerrepr_)util)Callabler_LOGGER _MAX_WORKERSg?_POLLING_PERIOD_SECScveZdZdZeeZed dZddd d dZ ddZ d d Z d d Z d d Z y)PollingPathWatcherz*Watches a path on disk via a polling loop.) max_workersc.tjdy)zClose top-level watcher object. This is a no-op, and exists for interface parity with EventBasedPathWatcher. zWatcher closedN)rdebugl/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/watcher/polling_path_watcher.py close_allzPollingPathWatcher.close_all+s  &'rNF glob_patternallow_nonexistentctt||_||_||_||_d|_t jt|j|j|_ t jt|j|j|j|_ |jy)zConstructor. You do not need to retain a reference to a PollingPathWatcher to prevent it from being garbage collected. (The global _executor object retains references to all active instances.) TrN) r_path _on_changed _glob_pattern_allow_nonexistent_activer path_modification_timestr_modification_timecalc_md5_with_blocking_retries_md5 _schedule)selfpath on_changedrrs r__init__zPollingPathWatcher.__init__4s$Z %)"3 "&"="=  OT44# 77  O++"55  rct|SNr r*s r__repr__zPollingPathWatcher.__repr__Us T{rcPdfd }tjj|y)NcXtjtjyr/)timesleepr_check_if_path_changedr0srtaskz*PollingPathWatcher._schedule..taskYs JJ+ ,  ' ' )rreturnNone)r _executorsubmit)r*r7s` rr)zPollingPathWatcher._scheduleXs * $$++D1rc|jsy tjt|j|j }|dk7r ||j kr|jy||_tjt|j|j|j }||jk(r|jy ||_ tjd|j|jt|j|jy#t$r,}tjd|j|Yd}~yd}~wwxYw)Ngrz9Ignoring file change. Failed to calculate MD5 for path %s)exc_infozChange detected: %s)r#r r$r%rr"r&r)r'r!r(rrrr )r*modification_timemd5exs rr6z)PollingPathWatcher._check_if_path_changed_s ||   $ ; ;DJJ!8!8!  "S(%)@)@@ &7D #55DJJ!//"&"9"9C dii    +TZZ8 TZZ) (  MMK      sAD*'A%D** E3"EEcd|_y)zStop watching the file system.FN)r#r0s rclosezPollingPathWatcher.closes  rr8) r+r%r,zCallable[[str], None]rz str | Nonerboolr9r:)r9r%)__name__ __module__ __qualname____doc__rrr; staticmethodrr-r1r)r6rCrrrrr&st4"|rTs[5" 1'5' "(H%% e!e!ffr