コード例 #1
0
    async def _do_run(self, boot_info: BootInfo) -> None:
        with child_process_logging(boot_info):
            endpoint_name = self.get_endpoint_name()
            event_bus_service = AsyncioEventBusService(
                boot_info.trinity_config,
                endpoint_name,
            )
            async with background_asyncio_service(event_bus_service):
                event_bus = await event_bus_service.get_event_bus()

                try:
                    if boot_info.profile:
                        with profiler(f'profile_{self.get_endpoint_name()}'):
                            await self.do_run(boot_info, event_bus)
                    else:
                        # XXX: When open_in_process() injects a KeyboardInterrupt into us (via
                        # coro.throw()), we hang forever here, until open_in_process() times out
                        # and sends us a SIGTERM, at which point we exit without executing either
                        # the except or the finally blocks below.
                        # See https://github.com/ethereum/trinity/issues/1711 for more.
                        await self.do_run(boot_info, event_bus)
                except KeyboardInterrupt:
                    # Currently we never reach this code path, but when we fix the issue above it
                    # will be needed.
                    return
                finally:
                    # Once we start seeing this in the logs, we'll likely have figured the issue
                    # above.
                    logger.debug("%s: do_run() finished", self)
コード例 #2
0
 def run_process(cls, boot_info: BootInfo) -> None:
     with child_process_logging(boot_info):
         if boot_info.profile:
             with profiler(f'profile_{cls.get_endpoint_name()}'):
                 trio.run(cls._do_run, boot_info)
         else:
             trio.run(cls._do_run, boot_info)
コード例 #3
0
    async def _do_run(self) -> None:
        with child_process_logging(self._boot_info):
            endpoint_name = self.get_endpoint_name()
            event_bus_service = AsyncioEventBusService(
                self._boot_info.trinity_config,
                endpoint_name,
            )
            async with background_asyncio_service(
                    event_bus_service) as eventbus_manager:
                event_bus = await event_bus_service.get_event_bus()
                loop_monitoring_task = create_task(
                    self._loop_monitoring_task(event_bus),
                    f'AsyncioIsolatedComponent/{self.name}/loop_monitoring_task'
                )

                do_run_task = create_task(
                    self.do_run(event_bus),
                    f'AsyncioIsolatedComponent/{self.name}/do_run')
                eventbus_task = create_task(
                    eventbus_manager.wait_finished(),
                    f'AsyncioIsolatedComponent/{self.name}/eventbus/wait_finished'
                )
                try:
                    max_wait_after_cancellation = 2
                    tasks = [do_run_task, eventbus_task, loop_monitoring_task]
                    if self._boot_info.profile:
                        with profiler(f'profile_{self.get_endpoint_name()}'):
                            await wait_first(tasks,
                                             max_wait_after_cancellation)

                    else:
                        # XXX: When open_in_process() injects a KeyboardInterrupt into us (via
                        # coro.throw()), we hang forever here, until open_in_process() times
                        # out and sends us a SIGTERM, at which point we exit without executing
                        # either the except or the finally blocks below.
                        # See https://github.com/ethereum/trinity/issues/1711 for more.
                        try:
                            await wait_first(
                                tasks,
                                max_wait_after_cancellation,
                            )
                        except asyncio.TimeoutError:
                            self.logger.warning(
                                "Timed out waiting for tasks to terminate after cancellation: %s",
                                tasks)

                except KeyboardInterrupt:
                    self.logger.debug("%s: KeyboardInterrupt", self)
                    # Currently we never reach this code path, but when we fix the issue above
                    # it will be needed.
                    return
                finally:
                    # Once we start seeing this in the logs after a Ctrl-C, we'll likely have
                    # figured out the issue above.
                    self.logger.debug("%s: do_run() finished", self)
コード例 #4
0
async def run_db_manager(
        boot_info: BootInfo, get_base_db_fn: Callable[[BootInfo],
                                                      LevelDB]) -> None:
    with child_process_logging(boot_info):
        trinity_config = boot_info.trinity_config
        manager = DBManager(get_base_db_fn(boot_info))
        with trinity_config.process_id_file('database'):
            with manager.run(trinity_config.database_ipc_path):
                loop = asyncio.get_event_loop()
                try:
                    await loop.run_in_executor(None, manager.wait_stopped)
                finally:
                    # We always need to call stop() before returning as asyncio can't cancel the
                    # thread started by run_in_executor() and that would prevent
                    # open_in_process(run_db_manager, ...) from returning.
                    manager.stop()
コード例 #5
0
ファイル: trio.py プロジェクト: marcgarreau/trinity
 async def _do_run(self) -> None:
     with child_process_logging(self._boot_info):
         event_bus_service = TrioEventBusService(
             self._boot_info.trinity_config,
             self.get_endpoint_name(),
         )
         async with background_trio_service(event_bus_service):
             event_bus = await event_bus_service.get_event_bus()
             async with trio.open_nursery() as nursery:
                 nursery.start_soon(self.run_process, event_bus)
                 try:
                     await trio.sleep_forever()
                 except KeyboardInterrupt:
                     self.logger.debug("%s: Got KeyboardInterrupt, exiting",
                                       self.name)
                     nursery.cancel_scope.cancel()
コード例 #6
0
    async def _do_run(cls, boot_info: BootInfo) -> None:
        with child_process_logging(boot_info):
            endpoint_name = cls.get_endpoint_name()
            event_bus_service = AsyncioEventBusService(
                boot_info.trinity_config,
                endpoint_name,
            )
            async with background_asyncio_service(event_bus_service):
                event_bus = await event_bus_service.get_event_bus()

                try:
                    if boot_info.profile:
                        with profiler(f'profile_{cls.get_endpoint_name()}'):
                            await cls.do_run(boot_info, event_bus)
                    else:
                        await cls.do_run(boot_info, event_bus)
                except KeyboardInterrupt:
                    return
コード例 #7
0
ファイル: main.py プロジェクト: AYCH-Inc/aych.eth.client
def run_database_process(boot_info: BootInfo, db_class: Type[LevelDB]) -> None:
    with child_process_logging(boot_info):
        trinity_config = boot_info.trinity_config

        with trinity_config.process_id_file('database'):
            app_config = trinity_config.get_app_config(Eth1AppConfig)

            base_db = db_class(db_path=app_config.database_dir)
            chaindb = ChainDB(base_db)

            if not is_database_initialized(chaindb):
                chain_config = app_config.get_chain_config()
                initialize_database(chain_config, chaindb, base_db)

            manager = DBManager(base_db)
            with manager.run(trinity_config.database_ipc_path):
                try:
                    manager.wait_stopped()
                except KeyboardInterrupt:
                    pass
コード例 #8
0
    async def _do_run(self) -> None:
        with child_process_logging(self._boot_info):
            endpoint_name = self.get_endpoint_name()
            event_bus_service = AsyncioEventBusService(
                self._boot_info.trinity_config,
                endpoint_name,
            )
            async with background_asyncio_service(event_bus_service):
                event_bus = await event_bus_service.get_event_bus()

                try:
                    if self._boot_info.profile:
                        with profiler(f'profile_{self.get_endpoint_name()}'):
                            await self.do_run(event_bus)
                    else:
                        # XXX: When open_in_process() injects a KeyboardInterrupt into us (via
                        # coro.throw()), we hang forever here, until open_in_process() times out
                        # and sends us a SIGTERM, at which point we exit without executing either
                        # the except or the finally blocks below.
                        # See https://github.com/ethereum/trinity/issues/1711 for more.
                        await self.do_run(event_bus)
                except KeyboardInterrupt:
                    # Currently we never reach this code path, but when we fix the issue above it
                    # will be needed.
                    return
                except BaseException:
                    # Leaving trinity running after a component crashes can lead to unexpected
                    # behavior that'd be hard to debug/reproduce, so for now we shut it down if
                    # any component crashes unexpectedly.
                    event_bus.broadcast_nowait(ShutdownRequest(f"Unexpected error in {self}"))
                    # Because of an issue in the ComponentManager (see comment in
                    # _cleanup_component_task), when a component crashes and requests trinity to
                    # shutdown, there's still a chance its exception could be lost, so we log it
                    # here as well.
                    self.logger.exception(
                        "Unexpected error in component %s, shutting down trinity", self)
                    raise
                finally:
                    # Once we start seeing this in the logs after a Ctrl-C, we'll likely have
                    # figured out the issue above.
                    self.logger.debug("%s: do_run() finished", self)
コード例 #9
0
    async def _do_run(self) -> None:
        with child_process_logging(self._boot_info):
            endpoint_name = self.get_endpoint_name()
            event_bus_service = AsyncioEventBusService(
                self._boot_info.trinity_config,
                endpoint_name,
            )
            # FIXME: Must terminate component if event_bus_service terminates.
            async with background_asyncio_service(event_bus_service):
                event_bus = await event_bus_service.get_event_bus()
                loop_monitoring_task = create_task(
                    self._loop_monitoring_task(event_bus),
                    f'AsyncioIsolatedComponent/{self.name}/loop_monitoring_task'
                )

                # FIXME: Must terminate component if loop_monitoring_task terminates.
                async with cleanup_tasks(loop_monitoring_task):
                    try:
                        if self._boot_info.profile:
                            with profiler(
                                    f'profile_{self.get_endpoint_name()}'):
                                await self.do_run(event_bus)
                        else:
                            # XXX: When open_in_process() injects a KeyboardInterrupt into us (via
                            # coro.throw()), we hang forever here, until open_in_process() times
                            # out and sends us a SIGTERM, at which point we exit without executing
                            # either the except or the finally blocks below.
                            # See https://github.com/ethereum/trinity/issues/1711 for more.
                            await self.do_run(event_bus)
                    except KeyboardInterrupt:
                        # Currently we never reach this code path, but when we fix the issue above
                        # it will be needed.
                        return
                    finally:
                        # Once we start seeing this in the logs after a Ctrl-C, we'll likely have
                        # figured out the issue above.
                        self.logger.debug("%s: do_run() finished", self)