def setUp(self): super().setUp() self.sd = subprocessDummy() watchdog.subprocess = self.sd self.watchdog = watchdog.Watchdog(scripts = ['a', 'b', 'c']) self.watchdog.loop_time = 0.5 self.ftr = base.Future(self.watchdog) # hier startet jetzt der Watchdog-Thread
def observe_clean_app(dev, app, prop): import watchdog wd = watchdog.Watchdog(100000) import observer ob = observer.Observer("../err/") ob.set_app(app) ob.load("../model/", "../guis/", "../guis-extra/", config.extra_screens, config.extra_element_scrs) import testlib tlib = testlib.collect_pieces("../tlib/") tlib.set_app(app) tlib.assume_reached('signin', 'login', 'main') tlib.assume_reached('welcome', 'skip sign in / sign up', 'main') ob.tlib = tlib import microtest tlib.add_test(microtest.init_test(appdb.get_app(app))) init = tlib.find_test('meta', 'start app') logger.info("start once first") init.attempt(dev, ob, state.State(), tlib, None) st = state.State({'loggedin': '1', prop: '1'}) ob.update_state(dev, st) tlib.mark_succ(init, state.init_state, st) most_reached = tlib.get_reached(init) logger.info("start -> %s", most_reached) smgr = StateMgr(tlib, None, dev, ob, wd) logger.info("ready") ret = smgr.observe_and_clean(prop, st) if ret: logger.info("prop %s is clean now" % prop) else: logger.info("observe/clean error")
def watchdog(request): dog = wd.Watchdog() dog_d = dog.start() request.addfinalizer(lambda: _post_results(dog, request)) def _run(deferred_fun): deferred_fun().addCallback(lambda _: dog.stop()) return dog_d return _run
def main(): wd = watchdog.Watchdog(keypad_service, led_service) keypad_service.add_watchdog(wd) batteryService = bat.BatService(mqtt_service) loop = asyncio.get_event_loop() loop.create_task(connect()) loop.create_task(heart_beat()) loop.run_forever()
def get_watchdog(time_limit=-1, memory_limit=-1, finalize_file=None): """Setup up 'watchdog' process to monitor resources. Returns: watchdog_instance (object): watchdog instance """ watchdog_instance = watchdog.Watchdog(time_limit=time_limit, memory_limit=memory_limit * 1024 * 1024, finalize_file=finalize_file) return watchdog_instance
def __init__(self, protocol, listen_ip="0.0.0.0", listen_port=1110): self.protocol = protocol self.listen_ip = listen_ip self.listen_port = listen_port self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.listen_socket.bind((self.listen_ip, self.listen_port)) self.robot_state = robotstate.RobotState() self.connection_watchdog = watchdog.Watchdog(50, 1000, self.connection_timeout)
# Create a Ticker instance tick_obj = ticker.Ticker(tick_event=eventGoGetData, dt=dt, timeout=timeOut, tick_timeout_event=event_ticker_timeout) # Creates an AcquisitionSystem instance ASys = acquisition.AcquisitionSystem(sampling_funcs=samplingFunctions, maxRowsPerFile=maxCacheSize, channel_names=ch_names) # Creates a PreProcessor instance PrePross = pre_processor.PreProcessor(pre_process_func, channel_names=ch_names) # Create a Watchdog instance Watchdog = watchdog.Watchdog(ASys, PrePross, tick_obj, event_ticker_timeout) # Define threads ticker_thread = threading.Thread(name='Ticker', target=tick_obj.run) Acq_thread = threading.Thread(name='Acquisition', target=ASys.run, args=(eventGoGetData, eventFileReady, event_ticker_timeout), kwargs={'verbose': True}) PreProcess_thread = threading.Thread(name='Pre-Processor', target=PrePross.run, args=(eventFileReady, event_ticker_timeout), kwargs={'verbose': True})
def handle_console_cmd(cons, cmd, envs): threading.current_thread().name = 'MainThread' dev = envs['dev'] ob = envs['ob'] st = envs['state'] tlib = envs['tlib'] env = envs['env'] if 'app' in envs: app = envs['app'] else: app = 'cui' def save_stat(): tlib.save_stat(os.path.join("../stat/", "%s.txt" % app)) if cmd == 'q': save_stat() dev.finish() sys.exit(0) elif cmd == 'sense': scr = ob.grab_state(dev, no_verify=True, no_print=True) if scr.get('guess_descs') is None: util.print_tree(scr.get('tree')) else: util.print_tree(scr.get('tree'), scr.get('guess_descs'), scr.get('guess_score')) st.merge(scr) return elif cmd == 'tags': config.show_guess_tags = True scr = ob.grab_state(dev, no_verify=True, no_print=True) util.print_tree(scr.get('tree'), scr.get('guess_descs'), scr.get('guess_score')) st.merge(scr) config.show_guess_tags = False return elif cmd == 'tree': scr = ob.grab_state(dev, no_img=True) util.print_tree(scr.get('tree')) st.merge(scr) return elif cmd.startswith('app '): app = cmd.split(' ')[1] load_app(app, ob, tlib, envs) return elif cmd == 'load': tlib = testlib.collect_pieces("../tlib/") envs['tlib'] = tlib load_app(app, ob, tlib, envs) return elif cmd == 'reload': value.init_params("../etc/", app) try: if app: os.remove("../model/screen_%s" % app) os.remove("../model/element_%s" % app) else: os.remove("../model/screen") os.remove("../model/element") except: pass ob.load("../model/", "../guis/", "../guis-extra/", config.extra_screens, config.extra_element_scrs) return elif cmd == 'tlib': tlib = testlib.collect_pieces("../tlib/") envs['tlib'] = tlib return elif cmd == 'test': tlib = testlib.collect_pieces("../tlib/") tlib.set_app(app) tlib.add_test(microtest.init_test(appdb.get_app(app))) envs['tlib'] = tlib config.show_guess_tags = True scr = ob.grab_state(dev) config.show_guess_tags = False st.merge(scr) begin_state = st.to_essential(tlib.essential_props()) tests = tlib.usable_tests(st) tests.sort(key=lambda test: test.prio) for i in range(len(tests)): testinfo = tlib.get_testinfo(tests[i]) print("%2d. %s: %s [%d %d]" % (i, tests[i].feature_name, tests[i].name, testinfo.succs, testinfo.fails)) if len(tests) == 0: print("no test available!") return if len(tests) == 1: tid = 0 else: tid = input("which one? ") try: tid = int(tid) except: return test = tests[tid] ret = test.attempt(dev, ob, st, tlib, environ.empty) util.print_tree(st.get('tree'), st.get('guess_descs')) end_state = st.to_essential(tlib.essential_props()) if ret: print("test SUCC") tlib.clear_stat(test) tlib.mark_succ(test, begin_state, end_state) else: print("test FAIL") tlib.mark_fail(test, begin_state) save_stat() return elif cmd == 'save': save_stat() return elif cmd == 'stat': tlib.print_stat() return elif cmd == 'items': scr = ob.grab_state(dev, no_img=True) util.printitems(scr.get('items')) return elif cmd.startswith('item'): itemid = int(cmd.split(' ')[1]) scr = ob.grab_state(dev, no_img=True) items = scr.get('items') if itemid in items: print(util.describe(items[itemid])) else: print("no such item: %d" % itemid) return elif cmd == 'debug': logging.basicConfig(level=logging.DEBUG) return elif cmd == 'idle': dev.wait_idle() return elif cmd == 'dialog': scr = ob.grab_state(dev) ret = tlib.handle_dialog(scr, dev, ob) if ret: print("dialog handled") else: print("dialog not handled") return elif cmd.startswith('find '): tag = cmd.split(' ', 1)[1] con = concept.parse(tag) if con is None: print("invalid locator") return scr = ob.grab_state(dev) widgets = con.locate(scr, ob, environ.Environment()) if widgets == []: print("can't find") else: for widget in widgets: print("FOUND: %s" % widget) print(" content:", widget.content()) return elif cmd == 'perf': perfmon.print_stat() return elif cmd == 'clear': init = tlib.find_test('meta', 'start app') st.reset() init.attempt(dev, ob, st, tlib, None) ob.update_state(dev, st) tlib.mark_succ(init, state.init_state, st) return elif cmd.startswith('set'): parts = cmd.split(' ', 2) if len(parts) == 2: key = parts[1] val = "1" else: (key, val) = parts[1:] st.set(key, val) return elif cmd.startswith('del'): parts = cmd.split(' ', 1) key = parts[1] st.remove(key) return elif cmd == 'dump': filename = util.choose_filename("../cap/", "page%d") logger.info("dumping to page %s", filename) dev.dump(filename) #sense.dump_page(dev, "../cap/") return elif cmd == 'list': scr = ob.grab_state(dev, no_img=True) tree = scr.get('tree') treeinfo = analyze.collect_treeinfo(tree) for root in sorted(treeinfo['listlike']): print("ROOT:", util.describe_node(tree[root])) for item in sorted(treeinfo['itemlike']): if listinfo.get_lca(tree, [root, item]) == root: print(" NODE:", util.describe_node(tree[item])) for field in sorted(treeinfo['dupid']): if listinfo.get_lca(tree, [item, field]) == item: print(" FIELD:", util.describe_node(tree[field])) return elif cmd == 'webon': config.GRAB_WEBVIEW = True return elif cmd == 'weboff': config.GRAB_WEBVIEW = False return elif cmd.startswith('ob '): prop = cmd.split(' ', 1)[1] wd = watchdog.Watchdog(100000) smgr = statemgr.StateMgr(tlib, None, dev, ob, wd) ret = smgr.observe_prop(prop, st) if ret: print("prop %s = %s" % (prop, st.get(prop, ''))) else: print("observe error") return elif cmd.startswith('clean '): parts = cmd.split(' ', 2) if len(parts) == 2: prop = parts[1] val = "1" else: (prop, val) = parts[1:] wd = watchdog.Watchdog(100000) smgr = statemgr.StateMgr(tlib, None, dev, ob, wd) ret = smgr.cleanup_prop(prop, val, st) if ret: print("prop %s cleaned" % prop) else: print("clean error") return elif cmd.startswith('oc '): prop = cmd.split(' ', 1)[1] wd = watchdog.Watchdog(100000) smgr = statemgr.StateMgr(tlib, None, dev, ob, wd) ret = smgr.observe_and_clean(prop, st) if ret: print("prop %s is clean now" % prop) else: print("observe/clean error") return elif cmd == 'dbg': print(tlib) return elif cmd.startswith('skip '): name = cmd.split(' ', 1)[1] add_skip(app, name) print("skipping %s" % name) return elif cmd == 'skip': skips = load_skip(app) for skip in skips: print("now skipping %s" % skip) return elif cmd.startswith('noskip '): name = cmd.split(' ', 1)[1] del_skip(app, name) print("not skipping %s" % name) return elif cmd == 'src': if st.get('xml') is not None: print(st.get('xml')) if st.get('src') is not None: print(st.get('src')) return elif cmd == 'install': apputils.install(dev, app) return elif cmd == 'uninstall': apputils.uninstall(dev, app) return op = operation.parse_line(cmd) if op is None: print("unknown op") return ret = op.do(dev, ob, st, env, tlib) if not ret: print("op failed")
import triumvi # MQTT import paho.mqtt.client as mqtt # Called on every packet from the Triumvi def callback(pkt): watchdog.reset() try: json_pkt = json.dumps(pkt.dictionary) client.publish('gateway-data', json_pkt) except Exception as e: print('Error in callback with Triumvi packet') print(e) def watchdog_handler(): print("Watchdog expired. Haven't gotten a packet in a while.") os._exit(1) watchdog = watchdog.Watchdog(60, watchdog_handler) # Connect to the local MQTT broker client = mqtt.Client() client.connect('localhost', 1883, 60) # Start getting Triumvi Packets triumvi.triumvi(callback)
exec("from {0} import {0} as DONGLE".format(config['dongle']['type'])) sys.path.remove('dongles') if not "{}.py".format(config['car']['type']) in os.listdir('cars'): raise Exception('Unsupported car {}'.format(config['car']['type'])) sys.path.insert(0, 'cars') exec("from {0} import {0} as CAR".format(config['car']['type'])) sys.path.remove('cars') Threads = [] if 'watchdog' in config and config['watchdog'].get('enable') == True: import watchdog Watchdog = watchdog.Watchdog(config['watchdog']) else: Watchdog = None # Init dongle dongle = DONGLE(config['dongle'], watchdog = Watchdog) # Init GPS interface gps = GpsPoller() Threads.append(gps) # Init car car = CAR(config['car'], dongle, gps) Threads.append(car) # Init EVNotify
def main(pool): import requests, time, os, socket from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter print("* Check RNG reliability... ", end="") check_rng() print("OK") create_lock() import config as cfg cfg.pool = pool print("* Check framework reliability... ", end="") check_framework() print("OK") while True: cfg.pool = None def boundary(): for x in ("worker_mir2", "worker_dsd2"): __import__(x).clean_env() boundary() del boundary try: with requests.Session() as net_sess: retries = Retry(total=8, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) net_sess.mount("http://", HTTPAdapter(max_retries=retries)) net_sess.mount("https://", HTTPAdapter(max_retries=retries)) cfg.net_sess = net_sess print("* Register") url_register = urljoin(cfg.srv_url, "/register") ret = cfg.net_sess.post(url_register, json={ "hostname": socket.gethostname(), "version": cfg.cli_version }, timeout=8.0) if ret.status_code != 200: raise RuntimeError("Cannot connect to server: HTTP %d" % (ret.status_code, )) ret = ret.json() cfg.cli_id = ret["cli_id"] print("* Client ID=#%d" % (cfg.cli_id, )) with Boundary(): print("* Enter boundary") worker_type, worker_config, gene_type = ret[ "worker_type"], ret["worker_config"], ret["gene_type"] print("* worker_type=%r" % (worker_type, )) print("* worker_config=%r" % (worker_config, )) cfg.worker_type = worker_type cfg.worker_config = worker_config cfg.gene_type = gene_type import geneop geneop.load_type(gene_type) cfg.pool = pool cfg.dog = watchdog.Watchdog() cfg.dog.start() worker = __import__("worker_%s" % (worker_type, )) worker.pre_fn() while True: try: print("* Acquire GPU...") cfg.lock.acquire() print("* Got GPU!") print("* Asking for new task...") ret = send_rpc("get_task") action = ret["action"] if action == "wait": print("* No task available at this moment.") time.sleep( 3 if cfg.worker_type != "toy" else 0.1) elif action == "run": print("* Got new task, working...") task_id, gene = ret["task_id"], ret["gene"] cfg.hurdle_limit_list = ret.get( "hurdle_limit_list", None) result = worker.eval_fn(gene) print("* Task finished, submitting result...") send_rpc("submit_result", task_id, result) print("* Result submitted") finally: cfg.lock.release() except KeyboardInterrupt: print("* Got KeyboardInterrupt, killing watchdog...") if cfg.dog is not None: cfg.dog.request_stop = True cfg.dog.join() print("* Bye!") os._exit(0) except: print("* Got Exception, restarting...") traceback.print_exc() if cfg.dog is not None: cfg.dog.request_stop = True cfg.dog.join() print("* Restarted!")
def __init__(m): m.wd = watchdog.Watchdog("screen")