
    Jn6h                         d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z	m
Z
mZ ej                  dk\  rd dlmZ nd dlmZ  e
d      Z ed      Z e
d      Z G d	 d
      Z G d de      Zy)    N)ExecutorFuture)TYPE_CHECKINGAnyCallableTypeVarUnion)   
   )	ParamSpec_T_P_Rc                   b    e Zd ZdZdddeeef   dej                  dej                  fdZ	d
d	Z
y)	_WorkItemz
    Represents an item needing to be run in the executor.
    Copied from ThreadPoolExecutor (but it's private, so we're not going to rely on importing it)
    future
Future[_R]fnargskwargsc                 <    || _         || _        || _        || _        y N)r   r   r   r   )selfr   r   r   r   s        p/var/www/django-portfolio.reubendavern.link/venv/lib/python3.12/site-packages/asgiref/current_thread_executor.py__init__z_WorkItem.__init__   s      	    Nc                 (   d}| j                   j                         sy 	  | j                  | j                  i | j                  }| j                   j                  |       y # t        $ r'}| j                   j                  |       d } Y d }~y d }~ww xY w)NT)r   set_running_or_notify_cancelr   r   r   
set_resultBaseExceptionset_exception)r   __traceback_hide__resultexcs       r   runz_WorkItem.run#   sz    !{{779	+TWWdii74;;7F KK""6*  	KK%%c*D	s   &A! !	B*BBreturnN)__name__
__module____qualname____doc__r   r   r   r   r   r   r%    r   r   r   r      sH    


 RV
 ww	

 ))
+r   r   c                   v    e Zd ZdZddZddZdeeef   dej                  dej                  dd	fd
Zesd Zyy)CurrentThreadExecutorz
    An Executor that actually runs code in the thread it is instantiated in.
    Passed to other threads running async code, so they can run sync code in
    the thread they came from.
    r'   Nc                 v    t        j                         | _        t        j                         | _        d| _        y )NF)	threadingcurrent_thread_work_threadqueueQueue_work_queue_broken)r   s    r   r   zCurrentThreadExecutor.__init__8   s(    %446INr   c                 V   t        j                         | j                  k7  rt        d      |j	                  | j
                  j                         	 	 | j
                  j                         }||u r		 d| _        yt        |t              sJ |j                          ~K# d| _        w xY w)z
        Runs the code in the work queue until a result is available from the future.
        Should be run from the thread the executor is initialised in.
        z<You cannot run CurrentThreadExecutor from a different threadTN)r0   r1   r2   RuntimeErroradd_done_callbackr5   putgetr6   
isinstancer   r%   )r   r   	work_items      r   run_until_futurez&CurrentThreadExecutor.run_until_future=   s     ##%):)::N  	  !1!1!5!56
	  ,,002	&
  DL	 ")Y777   DLs   B ;$B 	B(r   r   r   r   c                     t        j                         | j                  k(  rt        d      | j                  rt        d      t               }t        ||g|i |}| j                  j                  |       |S )Nz@You cannot submit onto CurrentThreadExecutor from its own threadz/CurrentThreadExecutor already quit or is broken)	r0   r1   r2   r8   r6   r   r   r5   r:   )r   r   r   r   fr=   s         r   _submitzCurrentThreadExecutor._submitV   sv     ##%):)::R  <<PQQ (a5d5f5	Y'r   c                 .     | j                   |g|i |S r   )rA   )r   r   r   r   s       r   submitzCurrentThreadExecutor.submitr   s    4<<4T4V44r   r&   )r   zFuture[Any]r'   N)r(   r)   r*   r+   r   r>   r   r   r   r   r   rA   r   rC   r,   r   r   r.   r.   1   s\    
 2RV ww ))	
 
4 	5 r   r.   )r3   sysr0   concurrent.futuresr   r   typingr   r   r   r   r	   version_infor   typing_extensionsr   r   r   r   r.   r,   r   r   <module>rI      s_     
  / ? ?w +T]t_T]+ +@B5H B5r   