a
    ù!f¹  ã                   @   s@   d Z ddlZddlZddlmZ ddlmZ G dd„ deƒZ	dS )z*Module containing the SessionThread class.é    Né   )Úqueuec                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚSessionThreadc                 C   s$   || _ || _|  ¡  || _|| _d S ©N)Ú_sessionÚ_jobsÚ_create_workerÚ
_responsesÚ_exceptions)ÚselfZinitialized_sessionZ	job_queueZresponse_queueZexception_queue© r   úb/var/www/html/python-backend/venv/lib/python3.9/site-packages/requests_toolbelt/threaded/thread.pyÚ__init__   s
    zSessionThread.__init__c                 C   s4   t j| jt ¡ d| _d| j_d| j_| j ¡  d S )N)ÚtargetÚnameTr   )	Ú	threadingÚThreadÚ_make_requestÚuuidÚuuid4Ú_workerÚdaemonÚ_stateÚstart©r   r   r   r   r      s    þzSessionThread._create_workerc              
   C   s~   zlz| j jf i |¤Ž}W n6 tjyN } z| j ||f¡ W Y d }~nd }~0 0 | j ||f¡ W | j ¡  n| j ¡  0 d S r   )	r   ÚrequestÚexcÚRequestExceptionr
   Úputr	   r   Ú	task_done)r   ÚkwargsÚresponseÚer   r   r   Ú_handle_request   s    &zSessionThread._handle_requestc                 C   s8   z| j  ¡ }W n tjy&   Y q4Y n0 |  |¡ q d S r   )r   Ú
get_nowaitr   ÚEmptyr#   )r   r    r   r   r   r   &   s
    
zSessionThread._make_requestc                 C   s
   | j  ¡ S )z*Proxy to the thread's ``is_alive`` method.)r   Úis_aliver   r   r   r   r&   /   s    zSessionThread.is_alivec                 C   s   | j  ¡  dS )z&Join this thread to the master thread.N)r   Újoinr   r   r   r   r'   3   s    zSessionThread.joinN)	Ú__name__Ú
__module__Ú__qualname__r   r   r#   r   r&   r'   r   r   r   r   r   
   s   	
	r   )
Ú__doc__r   r   Zrequests.exceptionsÚ
exceptionsr   Z_compatr   Úobjectr   r   r   r   r   Ú<module>   s
   