Commit shared files to aoc py meta repo.
This commit is contained in:
39
monitor.py
39
monitor.py
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import hashlib
|
||||
import time
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def get_file_hash(filename):
|
||||
hasher = hashlib.sha256()
|
||||
with open(filename, 'rb') as f:
|
||||
hasher.update(f.read())
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def main(script_name, interval=1):
|
||||
last_hash = None
|
||||
process = None
|
||||
|
||||
while True:
|
||||
try:
|
||||
current_hash = get_file_hash(script_name)
|
||||
if current_hash != last_hash:
|
||||
last_hash = current_hash
|
||||
if process and process.poll() is None:
|
||||
process.terminate()
|
||||
print(f"Detected change in {script_name}, running script...")
|
||||
process = subprocess.Popen(['pypy3', script_name], shell=False)
|
||||
time.sleep(interval)
|
||||
except KeyboardInterrupt:
|
||||
if process:
|
||||
process.terminate()
|
||||
break
|
||||
except FileNotFoundError:
|
||||
print("The file was not found. Make sure the script name is correct.")
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1])
|
||||
1
monitor.py
Symbolic link
1
monitor.py
Symbolic link
@@ -0,0 +1 @@
|
||||
../aocpy/monitor.py
|
||||
Reference in New Issue
Block a user