Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
combinerefs.cpython-314.pyc84 linesDownload Raw Back to __pycache__
1+
2��if��p�Rt^RIt^RItRtRtRt]R8Xd]!]P^,4R#R#)aP34combinerefs path5 6A helper for analyzing PYTHONDUMPREFS output.7 8When the PYTHONDUMPREFS envar is set in a debug build, at Python shutdown9time Py_FinalizeEx() prints the list of all live objects twice:  first it10prints the repr() of each object while the interpreter is still fully intact.11After cleaning up everything it can, it prints all remaining live objects12again, but the second time just prints their addresses, refcounts, and type13names (because the interpreter has been torn down, calling repr methods at14this point can get into infinite loops or blow up).15 16Save all this output into a file, then run this script passing the path to17that file.  The script finds both output chunks, combines them, then prints18a line of output for each object still alive at the end:19 20    address refcnt typename repr21 22address is the address of the object, in whatever format the platform C23produces for a %p format code.24 25refcnt is of the form26 27    "[" ref "]"28 29when the object's refcount is the same in both PYTHONDUMPREFS output blocks,30or31 32    "[" ref_before "->" ref_after "]"33 34if the refcount changed.35 36typename is Py_TYPE(object)->tp_name, extracted from the second PYTHONDUMPREFS37output block.38 39repr is repr(object), extracted from the first PYTHONDUMPREFS output block.40CAUTION:  If object is a container type, it may not actually contain all the41objects shown in the repr:  the repr was captured from the first output block,42and some of the containees may have been released since then.  For example,43it's common for the line showing the dict of interned strings to display44strings that no longer exist at the end of Py_FinalizeEx; this can be recognized45(albeit painfully) because such containees don't have a line of their own.46 47The objects are listed in allocation order, with most-recently allocated48printed first, and the first object allocated printed last.49 50 51Simple examples:52 53    00857060 [14] str '__len__'54 55The str object '__len__' is alive at shutdown time, and both PYTHONDUMPREFS56output blocks said there were 14 references to it.  This is probably due to57C modules that intern the string "__len__" and keep a reference to it in a58file static.59 60    00857038 [46->5] tuple ()61 6246-5 = 41 references to the empty tuple were removed by the cleanup actions63between the times PYTHONDUMPREFS produced output.64 65    00858028 [1025->1456] str '<dummy key>'66 67The string '<dummy key>', which is used in dictobject.c to overwrite a real68key that gets deleted, grew several hundred references during cleanup.  It69suggests that stuff did get removed from dicts by cleanup, but that the dicts70themselves are staying alive for some reason. Nc#�l"�VF)p\VPV44V8XdVx�K(R#	R#5i�N)�bool�match)�fileiter�pat�71whilematch�lines&&& �Tools\scripts\combinerefs.py�readrQs,�������	�	�$�� �J�.��J��	�s�24c�@�\V4p\V\P!R4R4FpK	\P!R4p/p/p^p\V\P!R4R4FKpVP	V4pV'd$VP4wq�V&WX&V^,
pK?\
RV4KM	^p	\WR4F�pV	^,
p	VP	V4pV'gQhVP4wr�pW�9d\
RVP44K\\
VRR7W�V,8Xd\
R	V72,RR7M\
R73WH,:RV74:R2RR7\
W�V,4K�	\
R
Wi3,4R#)z^Remaining objects:$Fz([a-zA-Z\d]+) \[(\d+)\] (.*)z^Remaining object addresses:$z??? skipped:Tz*??? new object created while tearing down:� )�endz[%s]�[z->�]z%d objects before, %d afterN)�iterr�re�compiler�groups�print�rstrip)�f�fir	�crack�addr2rc�	addr2guts�before�m�addr�after�rc�gutss&           r75�combinefiler"XsV��	
�a��B��R����$;�<�e�D���E�
�J�J�6�7�E��G��I�
�F��R����$D�E�u�M���K�K�����34�8�8�:�0�D�$�-����a�K�F��.�$�'�
N�
�E��R��%��
��76���K�K������q�������$����>����
�N��
�d���
�����&�2�+�3�'���
�
�r�2��<�
�d�d�O�$�&�77�78'�6�/�799�:�c�|�\V4;_uu_4p\V4RRR4R# +'giR#;ir)�openr")�fnamers& r80�combiner'|s ��	
�e�����A��81����s�*�;	�__main__)�__doc__r�sysrr"r'�__name__�argv�r#r82�<module>r.sC��C2�J83�84��";�H��z���C�H�H�Q�K��r#
codekingpro/portable-devtools · Team Ai