new management. master launches subordinate bureaus in subprocesses.
parent
576e213193
commit
5d1df02ee0
@ -1 +1 @@
|
||||
from bureau import Bureau
|
||||
from .bureau import Bureau, add_command, add_api
|
||||
|
@ -0,0 +1,56 @@
|
||||
"""
|
||||
The Management - this module takes care of loading and running subordinate
|
||||
bureaus in the office organization. Bureaus are enabled in the file
|
||||
"~/.screenless/mgmt.ini":
|
||||
[mgmt]
|
||||
bureaus = ihr typing myburo and so on
|
||||
"""
|
||||
import configparser
|
||||
import importlib
|
||||
import multiprocessing
|
||||
import os
|
||||
import time
|
||||
|
||||
def mgmt():
|
||||
|
||||
basepath = os.path.expanduser("~/.screenless")
|
||||
if not os.path.exists(basepath):
|
||||
os.mkdir(basepath)
|
||||
os.chdir(basepath)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
procs = {}
|
||||
|
||||
try:
|
||||
config.read("mgmt.ini")
|
||||
org_chart = config["mgmt"]["bureaus"].split()
|
||||
except KeyError:
|
||||
config["mgmt"] = {"bureaus": "ihr typing"}
|
||||
with open("mgmt.ini", "w") as configfile:
|
||||
config.write(configfile)
|
||||
print("created new mgmt.ini config file. please modify this to suit.")
|
||||
org_chart = config["mgmt"]["bureaus"].split()
|
||||
|
||||
print("org chart:", org_chart)
|
||||
|
||||
for buro in org_chart:
|
||||
lib = importlib.import_module("bureau." + buro)
|
||||
# run lib.main() in a separate process
|
||||
proc = multiprocessing.Process(target=lib.main)
|
||||
procs[buro] = proc.start()
|
||||
|
||||
while True:
|
||||
for buro in org_chart:
|
||||
proc = procs[buro]
|
||||
if not proc.is_alive():
|
||||
print("bureau", buro, "has crashed! Call the consultants!")
|
||||
#TODO this should probably restart in some sensible way
|
||||
else:
|
||||
print("bureau", buro, "still running...")
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mgmt()
|
Loading…
Reference in New Issue