U if @ s d Z ddddddddgZd ZeZi fd dZdd Zdd Zd d ZdddZ dd Z G dd deZG dd deZ dadadd ZdS )a/ Drop-in replacement for the thread module. Meant to be used as a brain-dead substitute so that threaded code does not need to be rewritten for when the thread module is not present. Suggested usage is:: try: import _thread except ImportError: import _dummy_thread as _thread errorstart_new_threadexit get_ident allocate_lockinterrupt_mainLockTypeRLockl c C s t |t t krtdt |t t kr4tddaz| || W n. tk rZ Y n ddl}| Y nX datrdat dS )a Dummy implementation of _thread.start_new_thread(). Compatibility is maintained by making sure that ``args`` is a tuple and ``kwargs`` is a dictionary. If an exception is raised and it is SystemExit (which can be done by _thread.exit()) it is caught and nothing is done; all other exceptions are printed out by using traceback.print_exc(). If the executed function calls interrupt_main the KeyboardInterrupt will be raised when the function returns. z2nd arg must be a tuplez3rd arg must be a dictF NT) typetuple TypeErrordict_main SystemExit traceback print_exc _interruptKeyboardInterrupt)Zfunctionargskwargsr r 2/opt/alt/python38/lib64/python3.8/_dummy_thread.pyr s c C s t dS )z'Dummy implementation of _thread.exit().N)r r r r r r = s c C s dS )zDummy implementation of _thread.get_ident(). Since this module should only be used when _threadmodule is not available, it is safe to assume that the current process is the only thread. Thus a constant can be safely returned. r r r r r r A s c C s t S )z0Dummy implementation of _thread.allocate_lock().r r r r r r J s Nc C s | dk rt ddS )z-Dummy implementation of _thread.stack_size().Nz'setting thread stack size not supportedr )r )sizer r r stack_sizeN s r c C s t S )z0Dummy implementation of _thread._set_sentinel().r r r r r _set_sentinelT s r c @ sF e Zd ZdZdd ZdddZeZdd Zd d Zdd Z dd Z dS )r a Class implementing dummy implementation of _thread.LockType. Compatibility is maintained by maintaining self.locked_status which is a boolean that stores the state of the lock. Pickling of the lock, though, should not be done since if the _thread module is then used with an unpickled ``lock()`` from here problems could occur from this class not having atomic methods. c C s d| _ d S )NF locked_statusselfr r r __init__c s zLockType.__init__Nc C sH |dks|rd| _ dS | j s&d| _ dS |dkr@ddl}|| dS dS )a Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit. NTr F)r timesleep)r waitflagtimeoutr# r r r acquiref s zLockType.acquirec C s | d S N)release)r typvaltbr r r __exit__ s zLockType.__exit__c C s | j s td| _ dS )zRelease the dummy lock.FT)r r r r r r r) s zLockType.releasec C s | j S r( r r r r r locked s zLockType.lockedc C s* d| j rdnd| jj| jjtt| f S )Nz<%s %s.%s object at %s>r. Zunlocked)r __class__ __module____qualname__hexidr r r r __repr__ s zLockType.__repr__)Nr" )__name__r0 r1 __doc__r! r' __enter__r- r) r. r4 r r r r r X s c s: e Zd ZdZ fddZd fdd Z fdd Z ZS )r a Dummy implementation of threading._RLock. Re-entrant lock can be aquired multiple times and needs to be released just as many times. This dummy implemention does not check wheter the current thread actually owns the lock, but does accounting on the call counts. c s t d| _d S )Nr )superr! _levelsr r/ r r r! s zRLock.__init__Nr" c s$ t ||}|r | jd7 _|S )zEAquire the lock, can be called multiple times in succession. r )r8 r' r9 )r r% r&