|
7 | 7 | (session ids, SSE encoding, session management) runs with no sockets, threads, or subprocesses. |
8 | 8 | """ |
9 | 9 |
|
10 | | -import gc |
11 | | -import warnings |
12 | 10 | from collections.abc import AsyncIterator, Awaitable, Callable, Iterable |
13 | 11 | from contextlib import AbstractAsyncContextManager, asynccontextmanager |
14 | 12 | from typing import Any, Protocol |
@@ -347,26 +345,14 @@ def httpx_client_factory( |
347 | 345 | ) |
348 | 346 |
|
349 | 347 | transport = sse_client(f"{BASE_URL}/sse", httpx_client_factory=httpx_client_factory) |
350 | | - try: |
351 | | - async with Client( |
352 | | - transport, |
353 | | - read_timeout_seconds=read_timeout_seconds, |
354 | | - sampling_callback=sampling_callback, |
355 | | - list_roots_callback=list_roots_callback, |
356 | | - logging_callback=logging_callback, |
357 | | - message_handler=message_handler, |
358 | | - client_info=client_info, |
359 | | - elicitation_callback=elicitation_callback, |
360 | | - ) as client: |
361 | | - yield client |
362 | | - finally: |
363 | | - # SseServerTransport.connect_sse never closes its sse_stream_reader (handed to |
364 | | - # sse_starlette.EventSourceResponse, which does not aclose() its content on cancel). |
365 | | - # After teardown that reader is held only by a reference cycle through the connect_sse |
366 | | - # frame and its task objects; collecting twice runs the cycle's finalizers and then |
367 | | - # frees the reader while ResourceWarning is suppressed, instead of at an arbitrary |
368 | | - # later GC under pytest's error filter. One pass suffices on 3.11+; 3.10 needs both. |
369 | | - with warnings.catch_warnings(): |
370 | | - warnings.simplefilter("ignore", ResourceWarning) |
371 | | - gc.collect() |
372 | | - gc.collect() |
| 348 | + async with Client( |
| 349 | + transport, |
| 350 | + read_timeout_seconds=read_timeout_seconds, |
| 351 | + sampling_callback=sampling_callback, |
| 352 | + list_roots_callback=list_roots_callback, |
| 353 | + logging_callback=logging_callback, |
| 354 | + message_handler=message_handler, |
| 355 | + client_info=client_info, |
| 356 | + elicitation_callback=elicitation_callback, |
| 357 | + ) as client: |
| 358 | + yield client |
0 commit comments