
    \
j                         d dl Z d dlZd dlZd dlZd dlmZ  ed          Z G d d          Z ej        ej                    G d de          Z	dS )    N)debug_printdebug_mediac                       e Zd ZdZ e            Z ej                    Zd Z	d Z
d Zd Zd Zd Zd Zed	             Zd
S )MediaThreadaF  A thread that cleanly exits on interpreter shutdown, and provides
    a sleep method that can be interrupted and a termination method.

    :Ivariables:
        `_condition` : threading.Condition
            Lock _condition on all instance variables.
        `_stopped` : bool
            True if `stop` has been called.

    c                     t          j        | j        d          | _        t          j                    | _        d| _        d S )NT)targetdaemonF)	threadingThread_thread_run_thread	Condition
_condition_stoppedselfs    S/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/media/mediathreads.py__init__zMediaThread.__init__>   s7     't/?MMM#-//    c                     t           N)NotImplementedErrorr   s    r   runzMediaThread.runC   s    !!r   c                 ^   t           j        d         rt          j                     | j        5  | j                            |            d d d            n# 1 swxY w Y   |                                  | j        5  | j                            |            d d d            d S # 1 swxY w Y   d S )Ndebug_trace)pygletoptions_install_trace_threads_lock_threadsaddr   remover   s    r   r   zMediaThread._thread_runF   s$   >-( 	$!### 	$ 	$Md###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$


 	' 	'M  &&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's#   AAA:B""B&)B&c                 8    | j                                          d S r   )r   startr   s    r   r$   zMediaThread.startP   s    r   c                     t          d          sJ | j        5  d| _        | j                                         ddd           n# 1 swxY w Y   	 | j                                         dS # t          $ r Y dS w xY w)a  Stop the thread and wait for it to terminate.

        The `stop` instance variable is set to ``True`` and the condition is
        notified.  It is the responsibility of the `run` method to check
        the value of `stop` after each sleep or wait and to return if set.
        zMediaThread.stop()TN)_debugr   r   notifyr   joinRuntimeErrorr   s    r   stopzMediaThread.stopS   s     *+++++_ 	% 	% DMO""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%	L 	 	 	DD	s#   !AA
A
A- -
A;:A;c                     t          d|z            sJ | j        5  | j        s| j                            |           ddd           dS # 1 swxY w Y   dS )zWait for some amount of time, or until notified.

        :Parameters:
            `timeout` : float
                Time to wait, in seconds.

        zMediaThread.sleep(%r)N)r&   r   r   wait)r   timeouts     r   sleepzMediaThread.sleepd   s     -788888_ 	. 	.= .$$W---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   "AAAc                     t          d          sJ | j        5  | j                                         ddd           dS # 1 swxY w Y   dS )zInterrupt the current sleep operation.

        If the thread is currently sleeping, it will be woken immediately,
        instead of waiting the full duration of the timeout.
        zMediaThread.notify()N)r&   r   r'   r   s    r   r'   zMediaThread.notifyq   s     ,-----_ 	% 	%O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   A  AAc                     | j         5  t          | j                  }d d d            n# 1 swxY w Y   |D ]}|                                 d S r   )r   listr    r*   )clsthreadsthreads      r   atexitzMediaThread.atexit{   s     	) 	)3<((G	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	 	FKKMMMM	 	s   )--N)__name__
__module____qualname____doc__setr    r
   Lockr   r   r   r   r$   r*   r.   r'   classmethodr5    r   r   r   r   0   s        	 	 suuH"IN$$M  
" " "' ' '    ". . .% % %   [  r   r   c                   8     e Zd ZdZdZ fdZd Zd Zd Z xZ	S )PlayerWorkerThreadz$Worker thread for refilling players.g?c                 n    t                                                       t                      | _        d S r   )superr   r:   players)r   	__class__s    r   r   zPlayerWorkerThread.__init__   s(    uur   c                 0   	 | j         5  t          d                    t          j                                        sJ | j        r	 d d d            d S d}| j        rYd}t          | j                  D ]8}|                                }||j        k    r|	                    |           d}9|s| j
        }nt          d          sJ d }|dk    r|                     |           n|                     | j
                   d d d            n# 1 swxY w Y   )NTzPlayerWorkerThread: woke up @{}Fz%PlayerWorkerThread: No active players)r   r&   formattimer   rB   r1   get_write_sizemin_buffer_sizerefill	_nap_timer.   )r   
sleep_timefilledplayer
write_sizes        r   r   zPlayerWorkerThread.run   s   	/
  / /?FFty{{SSTTTTT= / / / / / / / /  
< &"F"&t|"4"4 * *%+%:%:%<%<
%(>>>"MM*555%)F! 4%)^
!"IJJJJJ!%J##JJz**** JJt~...5/ / / / / / / / / / / / / / /	/s   >DB+DDDc                     |J t          d          sJ | j        5  | j                            |           | j                                         d d d            d S # 1 swxY w Y   d S )Nz PlayerWorkerThread: player added)r&   r   rB   r!   r'   r   rN   s     r   r!   zPlayerWorkerThread.add   s    !!!899999_ 	% 	%LV$$$O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   4AA"%A"c                     t          d          sJ | j        5  || j        v r| j                            |           | j                                         d d d            d S # 1 swxY w Y   d S )Nz"PlayerWorkerThread: player removed)r&   r   rB   r"   r'   rQ   s     r   r"   zPlayerWorkerThread.remove   s    :;;;;;_ 	% 	%%%##F+++O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   =A##A'*A')
r6   r7   r8   r9   rK   r   r   r!   r"   __classcell__)rC   s   @r   r?   r?      ss        .. I     /  /  /D% % %% % % % % % %r   r?   )
rG   r5   r
   r   pyglet.utilr   r&   r   registerr?   r=   r   r   <module>rV      s   H        # # # # # # 
]	#	#P P P P P P P Pf " # # #8% 8% 8% 8% 8% 8% 8% 8% 8% 8%r   