
    Mh                     Z    d dl Z d dlZ G d de          Z G d de          Zd Zd ZdS )    Nc                   Z    e Zd ZdZ ej                    ZdZdZdZ	d Z
d Zd Zd Zd ZdS )	Singletona  A base class for a class of a singleton object.

    For any derived class T, the first invocation of T() will create the instance,
    and any future invocations of T() will return that instance.

    Concurrent invocations of T() from different threads are safe.
    Nc                    |                     dd          r-t          |          t          |          z   dk    s
J d            | j        s| j        >| j        5  | j        t          j                    | _        d d d            n# 1 swxY w Y   | j        sf| j        5  | j        s@t                              |           | _        | j        	                                 d | _	        d d d            n# 1 swxY w Y   | j        S )NsharedFr   z\Cannot use constructor arguments when accessing a Singleton without specifying shared=False.c                      d S N )argskwargss     X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/debugpy/common/singleton.py<lambda>z#Singleton.__new__.<locals>.<lambda>=   s    t     )
getlen	_instance_lock
_lock_lock	threadingRLockobject__new____init__)clsr
   r   s      r   r   zSingleton.__new__    s   
 ::h.. 	
3t99s6{{3Jq2P2P2P' 3Q2P2P } 	Dy ^ 6 6y($-O$5$5	6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
 = 	DY D D= D(.s(;(;
 ..000'C'CD D D D D D D D D D D D D D D }s%    BB	B	AC22C69C6c                    |                     dd          }| 5  |r5t          |           j        dus
J d            dt          |           _        nt          |           j        
J d            ddd           dS # 1 swxY w Y   dS )aI  Initializes the singleton instance. Guaranteed to only be invoked once for
        any given type derived from Singleton.

        If shared=False, the caller is requesting a singleton instance for their own
        exclusive use. This is only allowed if the singleton has not been created yet;
        if so, it is created and marked as being in exclusive use. While it is marked
        as such, all attempts to obtain an existing instance of it immediately raise
        an exception. The singleton can eventually be promoted to shared use by calling
        share() on it.
        r   TFz%Cannot access a non-shared Singleton.NzSingleton is already created.)poptype
_is_shared)selfr
   r   r   s       r   r   zSingleton.__init__A   s     Hd++ 	V 	V VJJ)666: 766(,T

%%Dzz,446U444	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	Vs   AA<<B B c                 R    t          |           j                                         | S )z1Lock this singleton to prevent concurrent access.)r   r   acquirer   s    r   	__enter__zSingleton.__enter__W   s"    T

  """r   c                 R    t          |           j                                         dS )z1Unlock this singleton to allow concurrent access.N)r   r   release)r   exc_type	exc_valueexc_tbs       r   __exit__zSingleton.__exit__\   s#    T

  """""r   c                 .    dt          |           _        dS )zEShare this singleton, if it was originally created with shared=False.TN)r   r   r!   s    r   sharezSingleton.share`   s     $T

r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r"   r(   r*   r	   r   r   r   r   	   s          !""JE IJ  BV V V,  
# # #% % % % %r   r   c                   p     e Zd ZdZ e            Z	  e            Z	  fdZed             Z	d Z
d Z xZS )ThreadSafeSingletonaZ  A singleton that incorporates a lock for thread-safe access to its members.

    The lock can be acquired using the context manager protocol, and thus idiomatic
    use is in conjunction with a with-statement. For example, given derived class T::

        with T() as t:
            t.x = t.frob(t.y)

    All access to the singleton from the outside should follow this pattern for both
    attributes and method calls. Singleton members can assume that self is locked by
    the caller while they're executing, but recursive locking of the same singleton
    on the same thread is also permitted.
    c                      t                      j        |i | t          t          |           j                  t          |           _        d S r   )superr   setr   readonly_attrs)r   r
   r   	__class__s      r   r   zThreadSafeSingleton.__init__   sD    $)&)))$'T

(A$B$BT

!!!r   c                     t          |           j        }|                    d          s
J d            |                                 d S )NF)blockingzThreadSafeSingleton accessed without locking. Either use with-statement, or if it is a method or property, mark it as @threadsafe_method or with @autolocked_method, as appropriate.)r   r   r    r$   )r   locks     r   assert_lockedz!ThreadSafeSingleton.assert_locked   sR    Dzz||U|++ 	
 	
2	
 	
 	

 	r   c                     t                               | |          }|t          |           j        t          |           j        z  vr+t          |dd          st                              |            |S )Nis_threadsafe_methodF)r   __getattribute__r   threadsafe_attrsr4   getattrr0   r9   r   namevalues      r   r<   z$ThreadSafeSingleton.__getattribute__   sg    ''d33T

3d4jj6OOPP5"8%@@ 8#11$777r   c                     |t          |           j        vs
J d            |t          |           j        vrt                              |            t
                              | ||          S )NzThis attribute is read-only.)r   r4   r=   r0   r9   r   __setattr__r?   s      r   rC   zThreadSafeSingleton.__setattr__   se    4::44446T444tDzz222--d333!!$e444r   )r+   r,   r-   r.   	frozensetr=   r4   r   staticmethodr9   r<   rC   __classcell__)r5   s   @r   r0   r0   e   s          !y{{
 Y[[NC C C C C   \  5 5 5 5 5 5 5r   r0   c                     d| _         | S )zMarks a method of a ThreadSafeSingleton-derived class as inherently thread-safe.

    A method so marked must either not use any singleton state, or lock it appropriately.
    T)r;   )funcs    r   threadsafe_methodrI      s     !%DKr   c                 `     t          j                   t           fd                        }|S )zAutomatically synchronizes all calls of a method of a ThreadSafeSingleton-derived
    class by locking the singleton for the duration of each call.
    c                 T    | 5   | g|R i |cd d d            S # 1 swxY w Y   d S r   r	   )r   r
   r   rH   s      r   lock_and_callz(autolocked_method.<locals>.lock_and_call   s      	/ 	/4.t...v..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   !!)	functoolswrapsrI   )rH   rL   s   ` r   autolocked_methodrO      sF    
 _T/ / / /  / r   )rM   r   r   r   r0   rI   rO   r	   r   r   <module>rP      s   
        Y% Y% Y% Y% Y% Y% Y% Y%x<5 <5 <5 <5 <5) <5 <5 <5~      r   