コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: component.py プロジェクト: simulationcoin/trinity
    def _run_process(cls, boot_info: BootInfo) -> None:
        setup_child_process_logging(boot_info)

        if boot_info.profile:
            with profiler(f'profile_{cls._get_endpoint_name}'):
                cls.run_process(boot_info)
        else:
            cls.run_process(boot_info)
コード例 #4
0
ファイル: trio.py プロジェクト: root-servers/trinity
 async def run_process(self, event_bus: EndpointAPI) -> None:
     try:
         if self._boot_info.profile:
             with profiler(f'profile_{self.get_endpoint_name()}'):
                 await self.do_run(event_bus)
         else:
             await self.do_run(event_bus)
     except (trio.Cancelled, trio.MultiError):
         # These are expected, when trinity is terminating because of a Ctrl-C
         raise
コード例 #5
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)
コード例 #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
    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)
コード例 #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,
            )
            # 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)
コード例 #9
0
 async def run_process(self, event_bus: EndpointAPI) -> None:
     try:
         if self._boot_info.profile:
             with profiler(f'profile_{self.get_endpoint_name()}'):
                 await self.do_run(event_bus)
         else:
             await self.do_run(event_bus)
     except (trio.Cancelled, trio.MultiError):
         # These are expected, when trinity is terminating because of a Ctrl-C
         raise
     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
コード例 #10
0
ファイル: plugin.py プロジェクト: renaynay/trinity
 def _prepare_spawn(self) -> None:
     if self.boot_info.boot_kwargs.pop('profile', False):
         with profiler(f'profile_{self.normalized_name}'):
             self._spawn_start()
     else:
         self._spawn_start()
コード例 #11
0
 async def run_process(self, event_bus: EndpointAPI) -> None:
     if self._boot_info.profile:
         with profiler(f'profile_{self.get_endpoint_name()}'):
             await self.do_run(event_bus)
     else:
         await self.do_run(event_bus)