How to use the anyio.run_sync_in_worker_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_signals.py View on Github external
async def test_receive_signals():
    async with open_signal_receiver(signal.SIGUSR1, signal.SIGUSR2) as sigiter:
        await run_sync_in_worker_thread(os.kill, os.getpid(), signal.SIGUSR1)
        await run_sync_in_worker_thread(os.kill, os.getpid(), signal.SIGUSR2)
        assert await sigiter.__anext__() == signal.SIGUSR1
        assert await sigiter.__anext__() == signal.SIGUSR2
github agronholm / anyio / tests / test_threads.py View on Github external
async def test_run_in_thread_exception():
    def thread_worker():
        raise ValueError('foo')

    with pytest.raises(ValueError) as exc:
        await run_sync_in_worker_thread(thread_worker)

    exc.match('^foo$')
github agronholm / anyio / tests / test_threads.py View on Github external
async def task_worker():
        await run_sync_in_worker_thread(thread_worker, limiter=limiter)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def flush(self) -> None:
        return await anyio.run_sync_in_worker_thread(self._fp.flush)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def tell(self) -> int:
        return await anyio.run_sync_in_worker_thread(self._fp.tell)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def readinto1(self, b: Union[bytes, memoryview]) -> bytes:
        return await anyio.run_sync_in_worker_thread(self._fp.readinto1, b)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def write(self, b: bytes) -> None:
        return await anyio.run_sync_in_worker_thread(self._fp.write, b)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def truncate(self, size: Optional[int] = None) -> int:
        return await anyio.run_sync_in_worker_thread(self._fp.truncate, size)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def aclose(self) -> None:
        return await anyio.run_sync_in_worker_thread(self._fp.close)
github agronholm / anyio / src / anyio / fileio.py View on Github external
async def writelines(self, lines: bytes) -> None:
        return await anyio.run_sync_in_worker_thread(self._fp.writelines, lines)