Get or create a thread-local sync client. This is the recommended way to get a client in sync HTTP workers. Args: timeout: Timeout for operations in seconds Returns: DirtyClient: Thread-local client instance Example:: from gunicorn.dirty import get_d
(timeout=30.0)
| 679 | |
| 680 | |
| 681 | def get_dirty_client(timeout=30.0) -> DirtyClient: |
| 682 | """ |
| 683 | Get or create a thread-local sync client. |
| 684 | |
| 685 | This is the recommended way to get a client in sync HTTP workers. |
| 686 | |
| 687 | Args: |
| 688 | timeout: Timeout for operations in seconds |
| 689 | |
| 690 | Returns: |
| 691 | DirtyClient: Thread-local client instance |
| 692 | |
| 693 | Example:: |
| 694 | |
| 695 | from gunicorn.dirty import get_dirty_client |
| 696 | |
| 697 | def my_view(request): |
| 698 | client = get_dirty_client() |
| 699 | result = client.execute("myapp.ml:MLApp", "inference", data) |
| 700 | return result |
| 701 | """ |
| 702 | client = getattr(_thread_local, 'dirty_client', None) |
| 703 | if client is None: |
| 704 | socket_path = get_dirty_socket_path() |
| 705 | client = DirtyClient(socket_path, timeout=timeout) |
| 706 | _thread_local.dirty_client = client |
| 707 | return client |
| 708 | |
| 709 | |
| 710 | async def get_dirty_client_async(timeout=30.0) -> DirtyClient: |