def __init__(self, enabled=True):
        super(ProcessingQueueNode, self).__init__(enabled)

        self.read_queue = aioprocessing.AioQueue()
        self.write_queue = aioprocessing.AioQueue()
        self.lock = aioprocessing.AioLock()
        self.exit_event = aioprocessing.AioEvent()

        self.process = aioprocessing.AioProcess(
            target=self.processor_heavy_fn,
            args=(self.exit_event, self.lock, self.write_queue,
                  self.read_queue))
Beispiel #2
0
 def __init__(self, loop, pool, func, consumer, start_event,
              terminate_event):
     self.start_event = start_event
     self.terminate_event = terminate_event
     self.pool = pool
     self.func = func
     self.queue = aioprocessing.AioQueue()
     self.lock = aioprocessing.AioLock()
     self._event = aioprocessing.AioEvent()
     self.consumer = consumer
     self.loop = loop
     self.process = aioprocessing.AioProcess(
         target=GeneratorWorker.func_run,
         args=(self.loop, self.queue, self.lock, self._event, self.func))
def fork_and_start(main_function: Callable):
    """
    Forks a child process to run as the docker controller, and keep running the `main_function()` as the main process.

    When the `main_function()` exits, the child process is notified via `terminate_evt`, which will cause the child
    process to exit immediately as well. Afterwards, call join() and close() on the child process to ensure all acquired
    resources are freed up.
    """
    p1, p2 = aioprocessing.AioPipe()
    terminate_evt: aioprocessing.AioEvent = aioprocessing.AioEvent()
    docker_process: Process = Process(target=_docker_process_main,
                                      args=(p1, p2, terminate_evt))

    try:
        # fork the docker process as child.
        docker_process.start()

        # Set the pipe for docker_ipc() functions.
        set_hummingbot_pipe(p1)

        # run the main function as parent.
        main_function()

        # stop the gateway container.
        try:
            asyncio.get_event_loop().run_until_complete(
                docker_ipc("stop",
                           container=get_gateway_container_name(),
                           timeout=1))
        except Exception:
            pass
    finally:

        # close pipes.
        p1.close()
        p2.close()

        # set the terminate event.
        terminate_evt.set()

        # wait for Docker controller process to clean up.
        docker_process.join()
        docker_process.close()
Beispiel #4
0
 def __init__(self,
              app_log=None,
              config=None,
              verbose: bool = False,
              com_backend_class_name: str = 'TornadoBackend'):
     """Init the node components"""
     super().__init__(app_log, config, verbose)
     self.startup_time = time()
     self.connecting = False  # If true, manager tries to initiate outgoing connections to peers
     self.stop_event = aioprocessing.AioEvent()
     # load the backend class from the provided name
     backend_class = getattr(
         importlib.import_module(
             f"bismuthcore.{com_backend_class_name.lower()}"),
         com_backend_class_name)
     self._com_backend = backend_class(self,
                                       app_log=app_log,
                                       config=config,
                                       verbose=verbose)
     self._client_commands = ClientCommands(self)
     self._check()
     self._clients = {}  # outgoing connections
        print("Please edit config.txt, set mempool_ram_conf=False and restart node")
        sys.exit()
    """

    # TODO: print settings

    if not os.path.isfile(CONFIG.mempool_path):
        print("mempool.db not found at {}".format(CONFIG.mempool_path))
        print(
            "Please edit node's config.txt, check mempool_ram_conf=False and restart node."
        )
        sys.exit()

    start_time = time.time()

    stop_event = aioprocessing.AioEvent()  # Event()

    lock = aioprocessing.AioLock()

    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.INFO)
    # formatter = logging.Formatter('%(asctime)s %(funcName)s(%(lineno)d) %(message)s')
    # ch.setFormatter(formatter)
    app_log = logging.getLogger("tornado.application")
    tornado.log.enable_pretty_logging()
    # app_log.addHandler(ch)
    logfile = os.path.abspath("wallet_app.log")
    # Rotate log after reaching 512K, keep 5 old copies.
    rotateHandler = RotatingFileHandler(logfile, "a", 512 * 1024, 10)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    rotateHandler.setFormatter(formatter)
Beispiel #6
0
 def setUp(self):
     super().setUp()
     self.event = aioprocessing.AioEvent()
            break
        print("Got result {}".format(result))
    await p.coro_join()


async def example2(queue, event, lock):
    await event.coro_wait()
    async with lock:
        await queue.coro_put(78)
        await queue.coro_put(None)  # Shut down the worker


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    queue = aioprocessing.AioQueue()
    lock = aioprocessing.AioLock()
    event = aioprocessing.AioEvent()
    tasks = [
        asyncio.ensure_future(example(queue, event, lock)),
        asyncio.ensure_future(example2(queue, event, lock)),
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()

# endpoints = [1,2,2,3]
#
# queue_list = []
# for i, item in enumerate(endpoints):
#     queue_list.append(aioprocessing.AioQueue)
#
# print(queue_list)
Beispiel #8
0
    def __init__(self,
                 width,
                 height,
                 address=("10.76.76.1", 80),
                 enabled=True,
                 enable_images=True):
        super(WebsiteClient, self).__init__(enabled)
        # http://user:[email protected]/api/robot/rightcam

        self.address = address

        self.requested_width = width
        self.requested_height = height

        self.width = width
        self.height = height
        self.num_frames = 0

        self.reader = None
        self.writer = None

        self.enable_images = enable_images

        self.response_start_header = b'\xbb\x08'
        self.message_start_header = b'\xde\xad\xbe\xef'
        self.frame_len = 4
        self.timestamp_len = 8
        self.width_len = 2
        self.height_len = 2
        self.endian = 'big'

        self.chunk_size = int(self.width * self.height / 2)

        self.fps = 30.0
        self.length_sec = 0.0

        self.fps_sum = 0.0
        self.fps_avg = 30.0
        self.prev_t = None

        self.credentials = base64.b64encode(b'robot:naboris').decode('ascii')

        # self.manager = aioprocessing.AioSyncManager()

        self.connection = HTTPConnection("%s:%s" %
                                         (self.address[0], self.address[1]))

        self.headers = {
            'Content-type': 'image/jpeg',
            'Authorization': 'Basic %s' % self.credentials
        }

        if self.enable_images:
            self.connection.request("GET",
                                    "/api/robot/rightcam_meta",
                                    headers=self.headers)
            response = self.connection.getresponse()
        else:
            response = None

        self.image_process = aioprocessing.AioProcess(
            target=self.retrieve_images, args=(response, ))
        self.image_queue = aioprocessing.AioQueue()

        self.connection.request("GET", "/cmd", headers=self.headers)
        response = self.connection.getresponse()

        self.command_process = aioprocessing.AioProcess(
            target=self.retrieve_commands, args=(response, ))
        self.command_queue = aioprocessing.AioQueue()

        self.exit_event = aioprocessing.AioEvent()

        self.command_service_tag = "commands"
        self.define_service(self.command_service_tag, str)