+
     i  c                   sR    R t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt  ! R R4      t	R# )$Share a dictionary across processes.N)OptionalAny)loggerc                   s   a a ] tR t^ t oRtV 3R ltR tR tR tR t	V3R lR lt
RV3R	 lR
 lltV3R lR ltV3R lR ltR tRtVtV ;t# )
SharedDictr    c                s   < \         SV `  4        RV n        \        P                  ! 4       V n        RV n        \        P                  ! V P                  4       R# )zCreate a shared dictionary.g{Gz?N)
Zsuper__init___timeoutmultiprocessingZPipepipeprocessatexitZregister_stop)self	__class__s   &B/usr/lib/python3.14/site-packages/inputremapper/ipc/shared_dict.pyr   ZSharedDict.__init__%   s>     #((*	

#    c                s>   V P                   e9   V P                   P                  4       '       d   \        P                  ! R4       R# \        P                  ! R4       \        P
                  ! V P                  R7      V n         V P                   P                  4        R# )z7Ensure the process to manage the dictionary is running.Nz"SharedDict process already runningzStarting SharedDict process)Ztarget)r	   is_aliver   debugr   ZProcessmanagestartr      &r   r   ZSharedDict.start1   sc    <<#(=(=(?(?LL=> 	23&..dkkBr   c                s6   \         P                  ! R4       / p V P                  ^ ,          P                  4       p\         P                  ! RV4       V^ ,          R8X  d   R# V^ ,          R8X  d   V^,          W^,          &   V^ ,          R8X  d   VP	                  4        V^ ,          R8X  d9   V P                  ^ ,          P                  VP                  V^,          4      4       V^ ,          R8X  g   K  V P                  ^ ,          P                  R	4       EK  )
z6Manage the dictionary, handle read and write requests.zSharedDict process startedzSharedDict got %sstopNsetcleargetpingpong)r   r   r   recvr   sendr   )r   Zshared_dictZmessages   &  r   r   ZSharedDict.manage=   s    12iil'')GLL,g6qzV#qzU"*1!*AJ'qzW$!!#qzU"		!!!+//'!*"=>qzV#		!!!&)r   c                J    V P                   ^,          P                  R4       R# )zStop the managing process.N)r   r   r   r   r   r   r   ZSharedDict._stopT   s    		!)$r   c                r   )zClears the memory.N)r   r   r   r   r   _clearZSharedDict._clearX   s    		!*%r   c                    < V ^8  d   QhRS[ /#    keystrZformat__classdict__   "r   __annotate__SharedDict.__annotate__\   s      s r   c                s    W,          # )zEGet a value from the dictionary.

If it doesn't exist, returns None.
 r   r$      &&r   r   ZSharedDict.get\   s    
 yr   c                s0   < V ^8  d   QhRS[ S[,          /# )r#   timeout)r   Zintr'   r)   r   r*   r+   c   s       r   c                s^   V P                   ^,          P                  R4       \        P                  ! V P                   ^,          .. . T;'       g    V P                  4       V P                   ^,          P	                  4       '       d%   V P                   ^,          P                  4       R8H  # R# )z(Check if the manager process is running.r   F)r   )r   r   selectr   pollr   )r   r/   r.   r   r   ZSharedDict.is_alivec   sv    		!)$tyy|nb"g.F.FG99Q<99Q<$$&&00r   c                s&   < V ^8  d   QhRS[ RS[/# )r#   r$   value)r&   r   r'   r)   r   r*   r+   l   s     / /s /3 /r   c                sN    V P                   ^,          P                  RW34       R# )   r   Nr   )r   r$   r2   s   &&&r   __setitem__ZSharedDict.__setitem__l   s    		!5#-.r   c                r!   r"   r%   r'   r)   r   r*   r+   o   s      s r   c                st   V P                   ^,          P                  RV34       \        P                  ! V P                   ^,          .. . V P                  4       V P                   ^,          P	                  4       '       d"   V P                   ^,          P                  4       # \        P                  ! R4       R# )r3   r   zselect.select timed outN)r   r   r0   r   r1   r   r   Zerrorr-   r.   r   __getitem__ZSharedDict.__getitem__o   sz    		!5#,'tyy|nb"dmm<99Q<99Q<$$&&./r   c                s&    V P                  4        R # N)r   r   r   r   __del__ZSharedDict.__del__y   s    

r   )r   r   r	   r6   )Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r   r   r   r    r   r   r4   r5   r7   Z__static_attributes__Z__classdictcell__Z__classcell__)r   r(   s   @@r   r   r       sS     .
$
*.%&  / /  r   r   )
r8   r
   r   r0   Ztypingr   r   Zinputremapper.logging.loggerr   r   r,   r   r   <module>r9      s'   * +      /Z Zr   