Get or create a context-local async client. This is the recommended way to get a client in async HTTP workers. Args: timeout: Timeout for operations in seconds Returns: DirtyClient: Context-local client instance Example:: from gunicorn.dirty import g
(timeout=30.0)
| 708 | |
| 709 | |
| 710 | async def get_dirty_client_async(timeout=30.0) -> DirtyClient: |
| 711 | """ |
| 712 | Get or create a context-local async client. |
| 713 | |
| 714 | This is the recommended way to get a client in async HTTP workers. |
| 715 | |
| 716 | Args: |
| 717 | timeout: Timeout for operations in seconds |
| 718 | |
| 719 | Returns: |
| 720 | DirtyClient: Context-local client instance |
| 721 | |
| 722 | Example:: |
| 723 | |
| 724 | from gunicorn.dirty import get_dirty_client_async |
| 725 | |
| 726 | async def my_view(request): |
| 727 | client = await get_dirty_client_async() |
| 728 | result = await client.execute_async("myapp.ml:MLApp", "inference", data) |
| 729 | return result |
| 730 | """ |
| 731 | try: |
| 732 | client = _async_client_var.get() |
| 733 | except LookupError: |
| 734 | socket_path = get_dirty_socket_path() |
| 735 | client = DirtyClient(socket_path, timeout=timeout) |
| 736 | _async_client_var.set(client) |
| 737 | return client |
| 738 | |
| 739 | |
| 740 | def close_dirty_client(): |
no test coverage detected