contentmonster/worker.py

35 lines
931 B
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"
config = MonsterConfig.fromFile(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-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)
try:
shore = ShoreThread(state, config.directories)
2021-11-22 10:14:38 +00:00
shore.run()
except KeyboardInterrupt:
print("Keyboard interrupt received - stopping threads")
for thread in threads:
thread.kill()
exit()