Viewing File: /opt/hc_python/lib/python3.12/site-packages/greenlet/tests/__pycache__/test_leaks.cpython-312.pyc

�

`�*j*K���dZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZdd
lmZej sJ�Gd�de�Zd
�ZGd�de�Zedk(red�j/�yy)z)
Testing scenarios that may have leaked.
�N�)�TestCase)�PY314)�RUNNING_ON_FREETHREAD_BUILD)�WIN)�fails_leakcheck)�ignores_leakcheck)�RUNNING_ON_MANYLINUXc�<�eZdZe�Zd�Zd�Zd�Zed��Z	y)�HasFinalizerTracksInstancesc��tj|�|_|jj	t|��y�N)�sys�intern�msg�EXTANT_INSTANCES�add�id)�selfrs  �J/opt/hc_python/lib64/python3.12/site-packages/greenlet/tests/test_leaks.py�__init__z$HasFinalizerTracksInstances.__init__s)���:�:�c�?������!�!�"�T�(�+�c�L�|jjt|��yr)r�remover�rs r�__del__z#HasFinalizerTracksInstances.__del__ s�����$�$�R��X�.rc�6�dt|�|jfzS)Nz(<HasFinalizerTracksInstances at 0x%x %r>)rrrs r�__repr__z$HasFinalizerTracksInstances.__repr__"s!��9��t�H�d�h�h�=
�
�	
rc�8�|jj�yr)r�clear)�clss r�resetz!HasFinalizerTracksInstances.reset&s�����"�"�$rN)
�__name__�
__module__�__qualname__�setrrrr�classmethodr"�rrrrs-���u��,�/�
��%��%rrc�(�tr|St|�Sr)rr)�funcs r�&fails_leakcheck_except_on_free_thradedr++s��"����4� � rc���eZdZd�Zd�Zed��Zd�Zd�Zd�Z			dd�Z
d�Zd	�Ze
d
��Ze
d��Ze
d��Zd
Zd�Zed��Zdd�Zed��Zed��Zy)�	TestLeaksc���d}tj|�}tjd��}td�D]}|j|��|jtj|�|�y)N)�a�b�cc�X�tj�jj|�Sr��greenlet�
getcurrent�parent�switch)�argss r�<lambda>z)TestLeaks.test_arg_refs.<locals>.<lambda>:s!��=�(�-�-�/�6�6�=�=�t�Dr�d)r�getrefcountr4�ranger7�assertEqual)rr8�refcount_before�g�_s     r�
test_arg_refszTestLeaks.test_arg_refs5s]�����/�/�$�/�����D�
F���s��A��A�H�H�d�O���������.��@rc�6�i}|jtj|�tsdnd�t	jd��}td�D]}|jdi|���|jtj|�tsd�yd�y)N�rc�^�tj�jjdi|��S)Nr(r3)�gkwargss rr9z+TestLeaks.test_kwarg_refs.<locals>.<lambda>Ds$��A�h�1�1�3�:�:�A�A�L�G�Lrr:r()r=rr;rr4r<r7)r�kwargsr?r@s    r�test_kwarg_refszTestLeaks.test_kwarg_refs?sy�����������0�5�!�a�H����L�
N���s��A��A�H�H��v���	
�������0�5�!�H�a�Hrc��d�}tj|��}|j�tjd�|jd�y)Nc�.�tjd�y)N���MbP?)�time�sleepr(rr�workerz+TestLeaks.__recycle_threads.<locals>.workerTs���J�J�u�r��targetrJ�
)�	threading�Thread�startrKrL�join)rM�ts  r�__recycle_threadszTestLeaks.__recycle_threadsLs7��	����F�+��	���	��
�
�5��	���r�
rc���g��fd�}td�D]:}tj|��}|j�|j	d�~�<tj�|j�tj�tj�tj��D]}|j|���y)Nc�r���jtjtj���yr)�append�weakref�refr4r5)�ggs�rrMz,TestLeaks.test_threaded_leak.<locals>.worker]s!����I�I�g�k�k�(�"5�"5�"7�8�9rrCrNrP�r<rQrRrSrTr4r5�_TestLeaks__recycle_threads�gc�collect�assertIsNone�rrMr@rUr?r\s     @r�test_threaded_leakzTestLeaks.test_threaded_leak[s����
��	:��q��A�� � ��/�A�
�G�G�I�
�F�F�2�J��	�
	������� �����
�
�
�������A����a�c�"�rc���g��fd�}td�D]:}tj|��}|j�|j	d�~�<tj�|j�tj�tj�tj��D]}|j|���y)Nc����gx�tj�_�fd�}td�D]%}tj|�j	��'�jt
jtj���y)Nc�L���jtj��yr)rYr4r5)�lls�r�
additionalzDTestLeaks.test_threaded_adv_leak.<locals>.worker.<locals>.additionalrs����	�	�(�-�-�/�0rrC)r4r5rgr<r7rYrZr[)rhr@rgr\s  @�rrMz0TestLeaks.test_threaded_adv_leak.<locals>.workerosa���,.�.�B��$�$�&�)�
1��1�X���!�!�*�-�4�4�6���I�I�g�k�k�(�"5�"5�"7�8�9rrCrNrPr]rbs     @r�test_threaded_adv_leakz TestLeaks.test_threaded_adv_leakms����
��	:��q��A�� � ��/�A�
�G�G�I�
�F�F�2�J��	�
	������� �����
�
�
�������A����a�c�"�rc�V�tjj�}|j|d�tjj	d�tjj�}|j||�|j
tjjd�y)NrTr)r4�	_greenlet�&get_clocks_used_doing_optional_cleanup�assertGreaterEqual�enable_optional_cleanupr=�
assertGreater�CLOCKS_PER_SEC)r�used�used2s   r�assertClocksUsedzTestLeaks.assertClocksUsed�sz���!�!�H�H�J������a�(����2�2�4�8��"�"�I�I�K������u�%����8�-�-�<�<�a�@rc����	�
���
�tjg�sJ�tj�t	j
�|j
tjd��}tj��
tj��	g��fd��g�
�	�
���
�fd�}tj|��}|j��
jd�t	j
�|j
td��}t��dk(sJ�|j�d	j��dd�=�	j!�|j#d�~|j%�|j
td��}|j
tjd��}|j'||��s[tj(j+��=|j-||��r*|j-tj.t!��n	tj(j+��|j1�yy)
NF)�
exact_kindc�2��td�}tjjdtd���r2tj�j
j}||g�ytj�j
j
|g�y)NzDELETING STACK OBJECT�test_leaks_keyzDELETING THREAD STATE)rr4rk�set_thread_localr5r6r7)�jd�s�explicit_reference_to_switchs  �r�background_greenletz6TestLeaks._check_issue251.<locals>.background_greenlet�sv���,�-D�E�B����/�/� �+�,C�D�
F�
,��'�'�)�0�0�7�7���2�$���#�#�%�,�,�3�3�R�D�9rc�@��tj��}�jtj|j���j|�|j�~�j
��jd��rtj�yy)NrP)	r4rYrZr[r6r7r&�waitr5)�glet�background_glet_killed�background_glet_runningr|�background_greenlets�
bg_main_wrefs�manually_collect_backgrounds ������r�background_threadz4TestLeaks._check_issue251.<locals>.background_thread�sy����$�$�%8�9�D�� � ����T�[�[�!9�:� �'�'��-��K�K�M��#�'�'�)�"�'�'��+�
+��#�#�%�+rrNrPTrr)r_�
is_trackedrr"r4r5�
count_objectsrQ�EventrRrSr~�list�len�assertFalse�deadr&rT�wait_for_pending_cleanups�assertLessEqualrkrlr=rrs)rr�r{�greenlets_beforer�rU�lists_before�lists_after�greenlets_afterr�r�r|r�r�s ``      @@@@@r�_check_issue251zTestLeaks._check_issue251�s�����}�}�R� � � �#�)�)�+������-�-�h�.?�.?�E�-�R��"+�/�/�"3��!*���!2��!��	:��
�	&�	&�$
���$5�6��	���	��$�$�R�(������)�)�$�4�)�@���'�(�A�-�-�-����-�a�0�5�5�6�
!��#��"�"�$�	
���r�
�
�	
�&�&�(��(�(��$�(�?���,�,�X�->�->�5�,�Q��
	
���[�,�7�,��!�!�H�H�J�V����_�.>�?�*�� � �!<�!M�!M�s�u�U�
����D�D�F�R��!�!�#�Src�$�|j�yr�r�rs r�-test_issue251_killing_cross_thread_leaks_listz7TestLeaks.test_issue251_killing_cross_thread_leaks_lists�����rc���tjjd�	|j�tjjd�y#tjjd�wxYw)NFT)r4rkrnr�rs r�#test_issue251_with_cleanup_disabledz-TestLeaks.test_issue251_with_cleanup_disabledsP�����2�2�5�9�	=�� � �"����6�6�t�<��H���6�6�t�<�s�A�!A2c�(�|jd��y)NF�r�r�rs r�4test_issue251_issue252_need_to_collect_in_backgroundz>TestLeaks.test_issue251_issue252_need_to_collect_in_backgrounds��&	
�����?rc��d|_tjjd�	|j	d��tjjd�y#tjjd�wxYw)NTFr�)�expect_greenlet_leakr4rkrnr�rs r�Etest_issue251_issue252_need_to_collect_in_background_cleanup_disabledzOTestLeaks.test_issue251_issue252_need_to_collect_in_background_cleanup_disabled*s]��$(��!����2�2�5�9�	=�� � �U� �C����6�6�t�<��H���6�6�t�<�s�A�!A;c�*�|jdd��y)NFT)r�r{r�rs r�9test_issue251_issue252_explicit_reference_not_collectablezCTestLeaks.test_issue251_issue252_explicit_reference_not_collectable3s�����(-�)-�	�	/rr:c�d�tjddk\sJ�tr|jd�yy)Nr�z!Slow and not worth repeating here)r�version_infor
�skipTestrs r�_only_test_some_versionsz"TestLeaks._only_test_some_versions;s2������"�a�'�'�'���M�M�=�>� rc�`���|j�d��d���fd�}td�D]	}|��|j�}t|j�D]@}t	||j��}|�|j�}||ks�:|dkDs�@n|j|�y)Nc��y)Nrr(r(rr�fz:TestLeaks.test_untracked_memory_doesnt_increase.<locals>.fMs��r�'c�l��t��D]%}tj��j��'yr)r<r4r7)r@�ITERr�s ��r�run_itz?TestLeaks.test_untracked_memory_doesnt_increase.<locals>.run_itQs(����4�[���!�!�!�$�+�+�-�!rr�r)r�r<�get_process_uss�UNTRACK_ATTEMPTS�maxr�)rr�r@�
uss_before�count�	uss_afterr�r�s      @@r�%test_untracked_memory_doesnt_increasez/TestLeaks.test_untracked_memory_doesnt_increaseFs����	
�%�%�'�	���	.�
�q��A��H���)�)�+�
��4�0�0�1�E��Z��)=�)=�)?�@�J��H��,�,�.�I��J�&�5�1�9��
2�	
���Y�
�3rc�v��	�
���
�|j�|j�dg�	�	fd��d�
�
�fd��|�
G���
fd�d�}dx}}t|j�D�]}d�	d<|�}t	j
|��}|j
�|jd�|j|j��|�|j}t||j�}�r>|j|jd	�|j�	d�
|jz�~~�s|j�	dd��r|j�|j�}||ks��|d
kDs��n|j�|j�}t rdnd}|j#|||zdfz�y)
Nrc���	tj�jj�y#tj$r�dxxdz
cc<�wxYw)Nrr)r4r5r6r7�GreenletExit)�
EXIT_COUNTs�rr�z3TestLeaks._check_untracked_memory_thread.<locals>.ftsP���
��#�#�%�,�,�3�3�5����(�(�
��1�
��"�
��
�s	�,0�"Ar�c���g}t��D]8}tj��}|j|�|j��:|Sr)r<r4rYr7)�gletsr@r?r�r�s   ��rr�z8TestLeaks._check_untracked_memory_thread.<locals>.run_it}sC����E��4�[���%�%�a�(�����Q�����
�
!��Lrc�,��eZdZdxZZdZdZ���fd�Zy)�<TestLeaks._check_untracked_memory_thread.<locals>.ThreadFuncrr(rCc�>���j�|_t|j�D]%}|xjt���z
c_�'|jD]}�j
dt|����rd|_�j�|_y)Nzsuspended activer()	r�r�r<r�r��tuple�assertIn�strr�)rr@r?�deallocate_in_threadr��tests   ���r�__call__zETestLeaks._check_untracked_memory_thread.<locals>.ThreadFunc.__call__�sy���"&�"6�"6�"8����t�y�y�)�A��J�J�%���/�1�J�*����A��M�M�"4�c�!�f�=�$�(�!#�D�J�!%�!5�!5�!7��rN)r#r$r%r�r�r�r�r�)r�r�r�s���r�
ThreadFuncr��s���%&�&�J���E��D�
8rr�rN�r(rizafter attempts %d)r�r�r<r�rQrRrSrTr��is_aliver�r�r=r�r�r�rr�)rr�r�r�r�r��thread_funcrU�	tolerancer�r�r�r�r�s `       @@@@@r�_check_untracked_memory_threadz(TestLeaks._check_untracked_memory_threadhs�����%�%�'�	
�����S�
�	���
	���	8�	8�$"&�%�
�Y��4�0�0�1�E��J�q�M�$�,�K�� � ��4�A�
�G�G�I�
�F�F�2�J����Q�Z�Z�\�*��!�(�3�3�
��Z��)?�)?�@�J�#�� � ��!2�!2�B�7�� � ��A���{�7G�7G�0G�H���'�� � ��A���2�#��.�.�0��,�,�.�I��J�&�5�1�9��52�8	
�&�&�(��(�(�*�	�#&�J�1�	����Y�
�Y�(>�0�E�8�;�	=rc�(�|jd��y)NT�r�)r�rs r�Itest_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_threadzSTestLeaks.test_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_thread�s��	
�+�+��+�Frc�n�trtrtr|jd�|j	d��y)Nz6Windows 3.14t appears to leak. No other platform does.Fr�)rrrr�r�rs r�Gtest_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_mainzQTestLeaks.test_untracked_memory_doesnt_increase_unfinished_thread_dealloc_in_main�s*���.�5��M�M�R�S��+�+��+�GrN)TF)T)r#r$r%rArG�staticmethodr^rcrirsr�r�r�r+r�r�r�r�r�r	r�r�r�r�r(rrr-r-3s���A�
I�����#�$#�.A�59�5:�|$�|�=�,�@�,�@�(,�=�,�=�,�/�,�/�
��	?��4��4�>\=�|�G��G��H��Hrr-�__main__�unittest)�__doc__rr_rKrZrQr4�rrrr�	leakcheckrr	r
�GREENLET_USE_GC�objectrr+r-r#�
__import__�mainr(rr�<module>r�s�����	�������)��&�(�+�
�����
%�&�
%� !�hH��hH�T
�z���z����!�r
Back to Directory File Manager