
    h.                       S SK Jr  S SKrS SKrS SKrS SKrS SKJrJrJ	r	J
r
  S SKJr  S SKrS SKrS SKr\" S5      r\" S5      r\R$                  S:  a  \R&                  rO        SS jr        SS	 jrSS
 jrg)    )annotationsN)AnyTypeVarCallable	Awaitable)	ParamSpecT_RetvalT_ParamSpec)   	   c                  #    [         R                  R                  5       n[        R                  " 5       n[
        R                  " UR                  U /UQ70 UD6nUR                  SU5      I Sh  vN $  N7f)ao  Asynchronously run function *func* in a separate thread.

Any *args and **kwargs supplied for this function are directly passed
to *func*. Also, the current :class:`contextvars.Context` is propagated,
allowing context variables from the main thread to be accessed in the
separate thread.

Returns a coroutine that can be awaited to get the eventual result of *func*.
N)	asyncioeventsget_running_loopcontextvarscopy_context	functoolspartialrunrun_in_executor)funcargskwargsloopctx	func_calls         E/var/www/html/env/lib/python3.13/site-packages/openai/_utils/_sync.py_asyncio_to_threadr      s`      ~~..0&&(%%cggtEdEfE	))$	::::s   A.A70A51A7c                  #    [         R                  " 5       S:X  a  [        U /UQ70 UD6I S h  vN $ [        R                  R                  [        R                  " U /UQ70 UD65      I S h  vN $  NC N7f)Nr   )sniffiocurrent_async_libraryr   anyio	to_threadrun_syncr   r   )r   r   r   s      r   r#   r#   )   sn      $$&)3'>t>v>>>))$000   ?s!   ,A6A2>A6-A4.A64A6c                   ^  SU 4S jjnU$ )a  
Take a blocking function and create an async one that receives the same
positional and keyword arguments. For python version 3.9 and above, it uses
asyncio.to_thread to run the function in a separate thread. For python version
3.8, it uses locally defined copy of the asyncio.to_thread function which was
introduced in python 3.9.

Usage:

```python
def blocking_func(arg1, arg2, kwarg1=None):
    # blocking code
    return result


result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
```

## Arguments

`function`: a blocking regular callable (e.g. a function)

## Return

An async function that takes the same positional and keyword arguments as the
original one, that when called runs the same original function in a thread worker
and returns the result.
c                 >   >#    [        T/U Q70 UD6I S h  vN $  N7f)N)r#   )r   r   functions     r   wrapperasyncify.<locals>.wrapperS   s!     x9$9&9999s   )r   T_ParamSpec.argsr   T_ParamSpec.kwargsreturnr	    )r'   r(   s   ` r   asyncifyr.   5   s    <: N    )r   Callable[T_ParamSpec, T_Retval]r   r*   r   r+   r,   r   )r   r0   r   r*   r   r+   r,   r	   )r'   r0   r,   z*Callable[T_ParamSpec, Awaitable[T_Retval]])
__future__r   sysr   r   r   typingr   r   r   r   typing_extensionsr   r"   r    anyio.to_threadr	   r
   version_infor#   r   r.   r-   r/   r   <module>r7      s    " 
    4 4 '   :& v **;-;9I;Ug;	;$
)5EQc!r/   