o
    x¡·iÒ	  ã                   @  sn   d Z ddlmZ ddlZddlZddlmZmZ e e	¡Z
G dd„ dƒZddd„Zddd„ZG dd„ dƒZdS )zContext Keeper.é    )ÚannotationsN)ÚRecordÚResultc                   @  s8   e Zd ZU ded< ddd„Zddd„Zedd	d
„ƒZdS )ÚContextúthreading.EventÚ_cancel_eventÚreturnÚNonec                 C  s   t  ¡ | _d S ©N)Ú	threadingÚEventr   ©Úself© r   úN/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/internal/context.pyÚ__init__   ó   zContext.__init__c                 C  s   | j  ¡  d S r
   )r   Úsetr   r   r   r   Úcancel   r   zContext.cancelc                 C  s   | j S r
   )r   r   r   r   r   Úcancel_event   s   zContext.cancel_eventN©r   r	   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   r   Úpropertyr   r   r   r   r   r      s   
 

r   Úrecordr   r   Ústrc                 C  ó   | j j}|S r
   ©ÚcontrolÚmailbox_slot)r   Ú
context_idr   r   r   Úcontext_id_from_record   ó   r#   Úresultr   c                 C  r   r
   r   )r%   r"   r   r   r   Úcontext_id_from_result$   r$   r&   c                   @  sR   e Zd ZU ded< ddd„Zdd
d„Zddd„Zddd„Zddd„Zddd„Z	dS )ÚContextKeeperzdict[str, Context]Ú_active_itemsr   r	   c                 C  s
   i | _ d S r
   )r(   r   r   r   r   r   ,   s   
zContextKeeper.__init__r   r   úContext | Nonec                 C  s   t |ƒ}|sd S |  |¡}|S r
   )r#   Úadd)r   r   r"   Úcontext_objr   r   r   Úadd_from_record/   s
   
zContextKeeper.add_from_recordr"   r   r   c                 C  s   |sJ ‚t ƒ }|| j|< |S r
   )r   r(   )r   r"   r+   r   r   r   r*   :   s   
zContextKeeper.addc                 C  s   | j  |¡}|S r
   )r(   Úget©r   r"   Úitemr   r   r   r-   @   s   zContextKeeper.getc                 C  s   |sd S | j  |d ¡}d S r
   )r(   Úpop)r   r"   Ú_r   r   r   ÚreleaseD   s   zContextKeeper.releaseÚboolc                 C  s   |   |¡}|r| ¡  dS dS )NTF)r-   r   r.   r   r   r   r   I   s
   
zContextKeeper.cancelNr   )r   r   r   r)   )r"   r   r   r   )r"   r   r   r)   )r"   r   r   r	   )r"   r   r   r3   )
r   r   r   r   r   r,   r*   r-   r2   r   r   r   r   r   r'   )   s   
 




r'   )r   r   r   r   )r%   r   r   r   )Ú__doc__Ú
__future__r   Úloggingr   Úwandb.proto.wandb_internal_pb2r   r   Ú	getLoggerr   Úloggerr   r#   r&   r'   r   r   r   r   Ú<module>   s    


