Format: application/x-python-code
⬇ Download File (3.4 KB)
   1  o
   2  
   3  -h��@s�ddlZddlZddlZddlmZmZddlmZmZm	Z	m
   4  Z
   5  mZejdkr.ddlm
   6  Z
   7  nddlm
   8  Z
   9  e
  10  d�Ze
  11  d�Ze
  12  d�ZGd	d
  13  �d
  14  �ZGdd�de�ZdS)
  15  �N)�Executor�Future)�
  16  TYPE_CHECKING�Any�Callable�TypeVar�Union)��
  17  )�	ParamSpec�_T�_P�_Rc@s@eZdZdZdddeeefdejdejfdd�Z	d
  18  dd�Z
  19  d
  20  S)�	_WorkItemz�
  21      Represents an item needing to be run in the executor.
  22      Copied from ThreadPoolExecutor (but it's private, so we're not going to rely on importing it)
  23      �future�
  24  Future[_R]�fn�args�kwargscOs||_||_||_||_dS�N)rrrr)�selfrrrr�r�UC:\Users\shubh\Videos\agent\nova\Lib\site-packages\asgiref/current_thread_executor.py�__init__s
  25  z_WorkItem.__init__�returnNc
  26  Csrd}|j��s	dSz|j|ji|j��}Wnty0}z|j�|�d}WYd}~dSd}~ww|j�|�dS)NT)r�set_running_or_notify_cancelrrr�
  27  BaseException�
  28  set_exception�
  29  set_result)rZ__traceback_hide__�result�excrrr�run#s
  30  ��z
  31  _WorkItem.run�rN)�__name__�
  32  __module__�__qualname__�__doc__rr
  33  rrrrr!rrrrrs�
  34  ��
  35  �rc@sZeZdZdZddd�Zddd	�Zd
  36  eeefdej	dej
  37  dd
  38  fdd�Zes+dd�Z
  39  dSdS)�CurrentThreadExecutorz�
  40      An Executor that actually runs code in the thread it is instantiated in.
  41      Passed to other threads running async code, so they can run sync code in
  42      the thread they came from.
  43      rNcCst��|_t��|_d|_dS)NF)�	threading�current_thread�_work_thread�queue�Queue�_work_queue�_broken)rrrrr8s
  44  
  45  
  46  zCurrentThreadExecutor.__init__r�Future[Any]cCsht��|jkrtd��|�|jj�z	|j��}||ur#Wd|_dSt	|t
  47  �s*J�|��~qd|_w)z�
  48          Runs the code in the work queue until a result is available from the future.
  49          Should be run from the thread the executor is initialised in.
  50          z<You cannot run CurrentThreadExecutor from a different threadTN)r(r)r*�RuntimeError�add_done_callbackr-�put�getr.�
  51  isinstancerr!)rr�	work_itemrrr�run_until_future=s �
  52  
  53  ��	z&CurrentThreadExecutor.run_until_futurerrrrcOsRt��|jkrtd��|jrtd��t�}t||g|�Ri|��}|j�|�|S)Nz@You cannot submit onto CurrentThreadExecutor from its own threadz/CurrentThreadExecutor already quit or is broken)	r(r)r*r0r.rrr-r2)rrrr�fr5rrr�_submitVs�zCurrentThreadExecutor._submitcOs|j|g|�Ri|��Sr)r8)rrrrrrr�submitrszCurrentThreadExecutor.submitr")rr/rN)r#r$r%r&rr6rr
  54  rrrr8rr9rrrrr'1s 
  55  
  56  
  57  ���
  58  ��r')r+�sysr(�concurrent.futuresrr�typingrrrrr�version_inforZtyping_extensionsrr
  59  rrr'rrrr�<module>s
  60