def _on_controller_connected(self, aBrewPiController): controller = Controller(name="Serial BrewPi on {0} at {1}".format(platform.node(), aBrewPiController.serial_port), uri=self._make_controller_uri(aBrewPiController), description="A BrewPi connected to a serial port, using the legacy protocol.", connected=aBrewPiController.is_connected) send("controller.connected", aController=controller)
def exception_dead_mainthread(): def fake_is_alive(): return False def modify_isAlive(): MainThread.is_alive = fake_is_alive MainThread.isAlive = fake_is_alive for i in threading.enumerate(): if i.name == "MainThread": MainThread = i break send("STOP") time.sleep(5) threading.Thread(target=modify_isAlive).start() __run_queue() threading.Thread(target=__run_queue).start()
def callback(self, body): logging.info("execute %s" % body['event']) _id = body['args'][0] if settings.ROCKETTM_CALLBACK: send('results', {'_id': _id, 'status': 'processing'}) if not body['event'] in tasks.subs: if settings.ROCKETTM_CALLBACK: send('results', {'_id': _id, 'result': 'task not defined', 'status': 'finished', 'success': False}) return False result = [] for func, max_time2 in tasks.subs[body['event']]: logging.info("exec func: %s, timeout: %s" % (func, max_time2)) if max_time2 != -1: apply_max_time = max_time2 else: apply_max_time = self.max_time result.append(dict(self.safe_call(func, apply_max_time, body))) success = not any(r['success'] is False for r in result) send('results', {'_id': _id, 'status': 'finished', 'success': success, 'result': result}) return True
def print_message(*args, **kwargs): print "Example function1", args, kwargs @subscribe("Hello2") def print_message2(*args, **kwargs): import time time.sleep(4) print "Example function2", args, kwargs @subscribe("STOP") def dead_mainthread(*args, **kwargs): print "dead MainThread!" def other_example(*args, **kwargs): print "manual subscribe" send_thread("Hello1", text_example="new thread") send_queue("Hello2", text_example="normal run") send("Hello2", text_example="normal run") add_subscribe("Hello3", other_example) send_blocking("Hello3", text_example="blocking") print "Finish send all events" print "waiting stop"
def test_send(self): send("pepito", 1, 2, 3, example="added queue") self.assertEqual(True, True)
def timeout_exception(): send("STOP") time.sleep(10) threading.Thread(target=stop_new_thread).start() __run_queue() threading.Thread(target=__run_queue).start()
def stop_new_thread(*args, **kwargs): time.sleep(70) send("STOP")
def function3(*args, **kwargs): basicevents.send('test') return True
def _signal_controller_connected(self, new_controller): """ When a new controller has been detected """ controller = Controller() send("controller.connected", controller=controller)
def _on_controller_disconnected(self, aBrewPiController): send("controller.disconnected", aController=Controller(uri=self._make_controller_uri(aBrewPiController)))