def __init__(self, *args, **kwargs): # Path for dynamic spawning. self.root = os.path.dirname(__file__) # Get loop. self.loop = asyncio.get_event_loop() # Get remote objects URI. self.super_agility = lookup('worker1', 'super_agility') self.super_ares = lookup('worker3', 'super_ares') # Create a thread executor for slightly CPU-bound async functions. self.executor = ThreadPoolExecutor(20) # Init parent. super().__init__(*args, **kwargs)
def watch_logging(self): uri = lookup('database', 'logging') queue = Pyro4.Proxy(uri) while True: message = queue.get() topic = '{}.log'.format(Crossbar.prefix) self.publish(topic, *message)
import logging from logging.handlers import QueueHandler from cerebral.nameserver import lookup class Handler(QueueHandler): """ An asynchronous logger using a proxy-based queue. """ def prepare(self, record): # msg = self.format(record) msg = (record.levelno, record.msg) return msg # Configure pyro. Pyro4.config.SERIALIZER = 'pickle' # Connect to queue. uri = lookup('database', 'logging') proxy = Pyro4.Proxy(uri) proxy._pyroTimeout = 1.0 queue = Pyro4.async(proxy) # Configure logging. logger = logging.getLogger('universe') handler = Handler(queue) logger.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt='%(asctime)s | %(levelname)s | %(message)s', datefmt='%m/%d/%Y %H:%M:%S') handler.setFormatter(formatter) logger.addHandler(handler)
from cerebral import logger as l import logging import Pyro4 from ares.main import Ares from cerebral.nameserver import lookup, ports from cerebral.pack1.hippocampus import Android from threading import RLock, Thread, Event import time # Configure pyro. Pyro4.config.SERIALIZERS_ACCEPTED = frozenset(['pickle', 'serpent']) Pyro4.config.SERIALIZER = 'pickle' super_agility = Pyro4.Proxy(lookup('worker1', 'super_agility')) agility = Pyro4.Proxy(lookup('worker1', 'agility')) super_theia = Pyro4.Proxy(lookup('worker2', 'super_theia')) class SuperAres: def __init__(self): self.ares = Ares(Android.robot, Android.camera, Android.info) self.thread = None self.lock = RLock() self.event = Event() def start_follow(self): with self.lock: if self.thread is None: