diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d8ad873 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +sniffio==1.3.0 \ No newline at end of file diff --git a/structio/core/kernels/fifo.py b/structio/core/kernels/fifo.py index f9eb060..0cca494 100644 --- a/structio/core/kernels/fifo.py +++ b/structio/core/kernels/fifo.py @@ -18,6 +18,7 @@ from collections import deque from typing import Callable, Coroutine, Any from functools import partial import signal +import sniffio class FIFOKernel(BaseKernel): @@ -285,6 +286,7 @@ class FIFOKernel(BaseKernel): from tasks """ + old_name, sniffio.thread_local.name = sniffio.thread_local.name, "structio" try: func() except StopIteration as ret: @@ -324,6 +326,8 @@ class FIFOKernel(BaseKernel): task.state = TaskState.CRASHED self.event("on_exception_raised", task) self.on_error(task) + finally: + sniffio.thread_local.name = old_name def release_resource(self, resource: FdWrapper): self.io_manager.release(resource) diff --git a/tests/sniffio_test.py b/tests/sniffio_test.py new file mode 100644 index 0000000..63c16d6 --- /dev/null +++ b/tests/sniffio_test.py @@ -0,0 +1,11 @@ +import sniffio +import structio + + +async def main(): + backend = sniffio.current_async_library() + assert backend == "structio" + print(f"[main] Current async backend: {backend}") + + +structio.run(main)