Example #1
0
def pytest_fixture_post_finalizer(fixturedef, request):
    """Called after fixture teardown"""
    if fixturedef.argname == "event_loop":
        # Work around: pytest-asyncio sets an empty event loop policy here,
        # which breaks on windows, where we have to supply a specific
        # event loop policy. Until this is fixed in pytest-asyncio, manually re-set
        # the event policy here.
        # See also: https://github.com/pytest-dev/pytest-asyncio/pull/192
        asyncio.set_event_loop_policy(None)
        adjust_event_loop_policy()
Example #2
0
    def run(self):
        try:
            adjust_event_loop_policy()
            self.loop = loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            loop.set_debug(True)

            event_registry = EventRegistry()
            app = make_app(event_registry, self.shared_state)
            self.server = app.listen(address="127.0.0.1", port=self.port)
            # self.shared_state.set_server(self.server)

            asyncio.ensure_future(self.wait_for_stop())
            self.start_event.set()
            loop.run_forever()
        finally:
            self.loop.stop()
Example #3
0
    def make_local(cls, spec=None, cluster_kwargs=None, client_kwargs=None):
        """
        Spin up a local dask cluster

        interesting cluster_kwargs:
            threads_per_worker
            n_workers

        Returns
        -------
        DaskJobExecutor
            the connected JobExecutor
        """

        # Distributed doesn't adjust the event loop policy when being run
        # from within pytest as of version 2.21.0. For that reason we
        # adjust the policy ourselves here.
        adjust_event_loop_policy()

        if spec is None:
            from libertem.utils.devices import detect
            spec = cluster_spec(**detect())
        if client_kwargs is None:
            client_kwargs = {}
        if client_kwargs.get('set_as_default') is None:
            client_kwargs['set_as_default'] = False

        if cluster_kwargs is None:
            cluster_kwargs = {}
        if cluster_kwargs.get('silence_logs') is None:
            cluster_kwargs['silence_logs'] = logging.WARN

        cluster = dd.SpecCluster(workers=spec, **(cluster_kwargs or {}))
        client = dd.Client(cluster, **(client_kwargs or {}))

        client.wait_for_workers(len(spec))

        return cls(client=client, is_local=True, lt_resources=True)
Example #4
0
def fixup_event_loop():
    import nest_asyncio
    nest_asyncio.apply()
    adjust_event_loop_policy()