Skip to content

Commit 5af7dcb

Browse files
authored
Add watchdog that monitors scripts editing
1 parent b48dbcf commit 5af7dcb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

watcher.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import time
2+
from watchdog.observers import Observer
3+
from watchdog.events import PatternMatchingEventHandler
4+
5+
6+
class ScriptModifiedHandler(PatternMatchingEventHandler):
7+
patterns = ['*.py']
8+
9+
def __init__(self):
10+
super(ScriptModifiedHandler, self).__init__()
11+
# you can add some init code here
12+
13+
def process(self, event):
14+
print(event.src_path, event.event_type)
15+
16+
def on_modified(self, event):
17+
self.process(event)
18+
19+
def on_moved(self, event):
20+
pass
21+
22+
def on_deleted(self, event):
23+
pass
24+
25+
def on_created(self, event):
26+
pass
27+
28+
29+
if __name__ == '__main__':
30+
observer = Observer()
31+
path = '.'
32+
event_handler = ScriptModifiedHandler()
33+
observer.schedule(event_handler, path, recursive=True)
34+
observer.start()
35+
try:
36+
while True:
37+
time.sleep(1)
38+
except KeyboardInterrupt:
39+
observer.stop()
40+
observer.join()
41+

0 commit comments

Comments
 (0)