-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.py
More file actions
30 lines (25 loc) · 733 Bytes
/
watcher.py
File metadata and controls
30 lines (25 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import subprocess
import sys
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ChangeHandler(FileSystemEventHandler):
def __init__(self):
self.process = None
super().__init__()
def on_any_event(self, event):
if self.process:
self.process.terminate()
self.process = subprocess.Popen([sys.executable, 'app.py'])
def main():
event_handler = ChangeHandler()
observer = Observer()
observer.schedule(event_handler, path='./src', recursive=True)
observer.start()
try:
while True:
pass
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == "__main__":
main()