MCPcopy Create free account
hub / github.com/encode/starlette / current_task

Function current_task

tests/test_testclient.py:35–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33
34
35def current_task() -> Task[Any] | trio.lowlevel.Task:
36 # anyio's TaskInfo comparisons are invalid after their associated native
37 # task object is GC'd https://github.com/agronholm/anyio/issues/324
38 asynclib_name = sniffio.current_async_library()
39 if asynclib_name == "trio":
40 return trio.lowlevel.current_task()
41
42 if asynclib_name == "asyncio":
43 task = asyncio_current_task()
44 if task is None:
45 raise RuntimeError("must be called from a running task") # pragma: no cover
46 return task
47 raise RuntimeError(f"unsupported asynclib={asynclib_name}") # pragma: no cover
48
49
50def test_use_testclient_in_endpoint(test_client_factory: TestClientFactory) -> None:

Callers 1

lifespan_contextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected