�
u��gFD � �6 � d dl mZ d dlZd dlmZmZmZ d dlmZ d dl m
Z
mZmZ d dl
mZmZ d dlmZ d dlmZmZmZ d d lmZ d d
lmZmZmZmZmZ ddlmZ dd
l m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ej- dk r d dlm.Z.m/Z/ nd dl0m.Z.m/Z/ ed� � Z1 edd�� � Z2 e.d� � Z3d2d�Z4d3d �Z5 G d!� d"ee2 e� � Z6 G d#� d$e,� � Z7 G d%� d&� � Z8e G d'� d(� � � � Z9e d4d5d/�� � Z:d6d1�Z;dS )7� )�annotationsN)� Awaitable�Callable� Generator)�Future)�AbstractAsyncContextManager�AbstractContextManager�contextmanager)� dataclass�field)�isawaitable)�Lock�Thread� get_ident)�
TracebackType)�Any�Generic�TypeVar�cast�overload� )�
_eventloop)�get_async_backend�get_cancelled_exc_class�threadlocals)�Event)�CancelScope�create_task_group)�AsyncBackend)�
TaskStatus)� � )�TypeVarTuple�Unpack�T_Retval�T_coT)� covariant�PosArgsT�func�1Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]]�args�Unpack[PosArgsT]�returnc � � t j }t j }n# t $ r t d� � d�w xY w|� | ||�� � S )z�
Call a coroutine function from a worker thread.
:param func: a coroutine function
:param args: positional arguments for the callable
:return: the return value of the coroutine function
�9This function can only be run from an AnyIO worker threadN��token)r �current_async_backend�
current_token�AttributeError�RuntimeError�run_async_from_thread�r) r+ �
async_backendr1 s �a/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/anyio/from_thread.py�runr: ( si � ��$�:�
��*����� � � ��G�
�
�� �����
�.�.�t�T��.�G�G�G� � �6�&Callable[[Unpack[PosArgsT]], T_Retval]c � � t j }t j }n# t $ r t d� � d�w xY w|� | ||�� � S )z�
Call a function in the event loop thread from a worker thread.
:param func: a callable
:param args: positional arguments for the callable
:return: the return value of the callable
r/ Nr0 )r r2 r3 r4 r5 �run_sync_from_threadr7 s r9 �run_syncr? >