contentmonster/worker.py

41 lines
1 KiB
Python
Raw Normal View History

2021-11-20 14:40:07 +00:00
#!/usr/bin/env python3
from classes.config import MonsterConfig
from classes.vesselthread import VesselThread
2021-11-22 10:14:38 +00:00
from classes.shorethread import ShoreThread
2021-11-20 14:40:07 +00:00
from multiprocessing import Manager
import pathlib
2021-11-22 10:14:38 +00:00
import time
2021-11-20 14:40:07 +00:00
2021-11-22 10:14:38 +00:00
if __name__ == '__main__':
config_path = pathlib.Path(__file__).parent.absolute() / "settings.ini"
2021-11-25 15:31:49 +00:00
config = MonsterConfig()
config.readFile(config_path)
2021-11-20 14:40:07 +00:00
2021-11-22 10:14:38 +00:00
with Manager() as manager:
state = manager.dict()
state["files"] = manager.list()
2021-11-25 15:31:49 +00:00
state["config"] = config
2021-11-20 14:40:07 +00:00
2021-11-22 10:14:38 +00:00
threads = []
for vessel in config.vessels:
thread = VesselThread(vessel, state)
2021-11-22 10:14:38 +00:00
thread.start()
threads.append(thread)
2021-11-25 15:31:49 +00:00
shore = ShoreThread(state)
shore.start()
while True:
try:
time.sleep(10)
except KeyboardInterrupt:
print("Keyboard interrupt received - stopping threads")
shore.terminate()
for thread in threads:
thread.terminate()
exit()