-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher.py
36 lines (31 loc) · 1.12 KB
/
watcher.py
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
31
32
33
34
35
36
import time
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class FileWatcher(FileSystemEventHandler):
def __init__(self, script_path):
self.script_path = script_path
def on_modified(self, event):
if not event.is_directory:
# Stop the B script if it's running
subprocess.run(['pkill', '-f', 'verify.py'])
time.sleep(1) # Wait for the process to be terminated
# Call your existing script with the input and output folder paths
input_folder = './input'
output_folder = './output'
subprocess.run(['python3', 'verify.py', input_folder, output_folder])
def main():
input_folder = './input'
script_path = './verify.py'
event_handler = FileWatcher(script_path)
observer = Observer()
observer.schedule(event_handler, input_folder, recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == "__main__":
main()