How to use the anyio.run_async_from_thread function in anyio

To help you get started, we’ve selected a few anyio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agronholm / anyio / tests / test_threads.py View on Github external
def worker(*args):
        run_async_from_thread(sleep, *args)
        return True
github agronholm / anyio / tests / test_threads.py View on Github external
def worker(a, b):
        assert threading.get_ident() != event_loop_thread_id
        return run_async_from_thread(add, a, b)
github agronholm / anyio / tests / test_threads.py View on Github external
def thread_worker():
        nonlocal last_active
        run_async_from_thread(sleep_event.set)
        time.sleep(0.2)
        last_active = 'thread'
        run_async_from_thread(finish_event.set)
github Fuyukai / curious / curious / core / _ws_wrapper / universal_wrapper.py View on Github external
def _generator(self):
        """
        Runs the websocket generator. This is used by calling next() over it.
        """
        ws = WebSocket(self._url, agent=USER_AGENT)
        websocket = persist(ws, ping_rate=0, poll=1, exit_event=self._cancelled)
        self._ws = ws

        for item in websocket:
            # for some reason lomond doesn't exit the loop??
            if self._cancelled.is_set():
                break

            anyio.run_async_from_thread(self._queue.put, item)

        anyio.run_async_from_thread(self._queue.put, self._DONE)
github Fuyukai / curious / curious / core / _ws_wrapper / universal_wrapper.py View on Github external
def _generator(self):
        """
        Runs the websocket generator. This is used by calling next() over it.
        """
        ws = WebSocket(self._url, agent=USER_AGENT)
        websocket = persist(ws, ping_rate=0, poll=1, exit_event=self._cancelled)
        self._ws = ws

        for item in websocket:
            # for some reason lomond doesn't exit the loop??
            if self._cancelled.is_set():
                break

            anyio.run_async_from_thread(self._queue.put, item)

        anyio.run_async_from_thread(self._queue.put, self._DONE)