sniffio support
This commit is contained in:
parent
422304fcd9
commit
6f3394d7d6
|
@ -0,0 +1 @@
|
||||||
|
sniffio==1.3.0
|
|
@ -18,6 +18,7 @@ from collections import deque
|
||||||
from typing import Callable, Coroutine, Any
|
from typing import Callable, Coroutine, Any
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import signal
|
import signal
|
||||||
|
import sniffio
|
||||||
|
|
||||||
|
|
||||||
class FIFOKernel(BaseKernel):
|
class FIFOKernel(BaseKernel):
|
||||||
|
@ -285,6 +286,7 @@ class FIFOKernel(BaseKernel):
|
||||||
from tasks
|
from tasks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
old_name, sniffio.thread_local.name = sniffio.thread_local.name, "structio"
|
||||||
try:
|
try:
|
||||||
func()
|
func()
|
||||||
except StopIteration as ret:
|
except StopIteration as ret:
|
||||||
|
@ -324,6 +326,8 @@ class FIFOKernel(BaseKernel):
|
||||||
task.state = TaskState.CRASHED
|
task.state = TaskState.CRASHED
|
||||||
self.event("on_exception_raised", task)
|
self.event("on_exception_raised", task)
|
||||||
self.on_error(task)
|
self.on_error(task)
|
||||||
|
finally:
|
||||||
|
sniffio.thread_local.name = old_name
|
||||||
|
|
||||||
def release_resource(self, resource: FdWrapper):
|
def release_resource(self, resource: FdWrapper):
|
||||||
self.io_manager.release(resource)
|
self.io_manager.release(resource)
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue