U
    ÎZj¹  ã                   @   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   úd/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/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   sn   z\z| jjf |Ž}W n4 tjk
rH } z| j ||f¡ W 5 d }~X Y nX | j ||f¡ W 5 | j  ¡  X d S r   )	r   Ú	task_doner   ÚrequestÚexcÚRequestExceptionr
   Úputr	   )r   ÚkwargsÚresponseÚer   r   r   Ú_handle_request   s    "zSessionThread._handle_requestc                 C   s:   z| j  ¡ }W n tjk
r(   Y q6Y nX |  |¡ 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
   