MCPcopy Index your code
hub / github.com/plotly/dash / watch

Function watch

dash/_watch.py:7–36  ·  view source on GitHub ↗
(folders, on_change, pattern=None, sleep_time=0.1)

Source from the content-addressed store, hash-verified

5
6
7def watch(folders, on_change, pattern=None, sleep_time=0.1):
8 pattern = re.compile(pattern) if pattern else None
9 watched = collections.defaultdict(lambda: -1.0)
10
11 def walk():
12 walked = []
13 for folder in folders:
14 for current, _, files in os.walk(folder):
15 for f in files:
16 if pattern and not pattern.search(f):
17 continue
18 path = os.path.join(current, f)
19
20 info = os.stat(path)
21 new_time = info.st_mtime
22
23 if new_time > watched[path] > 0:
24 on_change(path, new_time, False)
25
26 watched[path] = new_time
27 walked.append(path)
28
29 # Look for deleted files
30 for w in [x for x in watched.keys() if x not in walked]:
31 del watched[w]
32 on_change(w, -1, True)
33
34 while True:
35 walk()
36 time.sleep(sleep_time)

Callers

nothing calls this directly

Calls 2

walkFunction · 0.85
compileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…