
    .PhU                         d Z ddlZddlZg dZd
dZdej        v Zer[ G d d          Z e            Z	  ed	          Z	dS )a  The Python Garbage Collector (`GC`_) doesn't usually get too much
attention, probably because:

  - Python's `reference counting`_ effectively handles the vast majority of
    unused objects
  - People are slowly learning to avoid implementing `object.__del__()`_
  - The collection itself strikes a good balance between simplicity and
    power (`tunable generation sizes`_)
  - The collector itself is fast and rarely the cause of long pauses
    associated with GC in other runtimes

Even so, for many applications, the time will come when the developer
will need to track down:

  - Circular references
  - Misbehaving objects (locks, ``__del__()``)
  - Memory leaks
  - Or just ways to shave off a couple percent of execution time

Thanks to the :mod:`gc` module, the GC is a well-instrumented entry
point for exactly these tasks, and ``gcutils`` aims to facilitate it
further.

.. _GC: https://docs.python.org/2/glossary.html#term-garbage-collection
.. _reference counting: https://docs.python.org/2/glossary.html#term-reference-count
.. _object.__del__(): https://docs.python.org/2/glossary.html#term-reference-count
.. _tunable generation sizes: https://docs.python.org/2/library/gc.html#gc.set_threshold
    N)get_all	GCToggler	toggle_gctoggle_gc_postcollectTc                 8    t           t                    st          d z            	 t          j                   }n# t
          $ r d}Y nw xY w|rt          j                   }nt          j                    }|r fd|D             }n fd|D             }|S )a  Get a list containing all instances of a given type.  This will
    work for the vast majority of types out there.

    >>> class Ratking(object): pass
    >>> wiki, hak, sport = Ratking(), Ratking(), Ratking()
    >>> len(get_all(Ratking))
    3

    However, there are some exceptions. For example, ``get_all(bool)``
    returns an empty list because ``True`` and ``False`` are
    themselves built-in and not tracked.

    >>> get_all(bool)
    []

    Still, it's not hard to see how this functionality can be used to
    find all instances of a leaking type and track them down further
    using :func:`gc.get_referrers` and :func:`gc.get_referents`.

    ``get_all()`` is optimized such that getting instances of
    user-created types is quite fast. Setting *include_subtypes* to
    ``False`` will further increase performance in cases where
    instances of subtypes aren't required.

    .. note::

      There are no guarantees about the state of objects returned by
      ``get_all()``, especially in concurrent environments. For
      instance, it is possible for an object to be in the middle of
      executing its ``__init__()`` and be only partially constructed.
    zexpected a type, not %rFc                 4    g | ]}t          |          |S  )
isinstance.0xtype_objs     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/gcutils.py
<listcomp>zget_all.<locals>.<listcomp>q   s(    >>>QjH&=&=>q>>>    c                 6    g | ]}t          |          u |S r	   )typer   s     r   r   zget_all.<locals>.<listcomp>s   s)    :::Qd1gg&9&9q&9&9&9r   )r
   r   	TypeErrorgc
is_trackedAttributeErrorget_referrersget_objects)r   include_subtypestype_is_trackedto_checkrets   `    r   r   r   D   s    B h%% >1H<=== -11        $#H-->## ;>>>>(>>>::::(:::Js   ? AA__pypy__c                   &    e Zd ZdZddZd Zd ZdS )r   a>  The ``GCToggler`` is a context-manager that allows one to safely
    take more control of your garbage collection schedule. Anecdotal
    experience says certain object-creation-heavy tasks see speedups
    of around 10% by simply doing one explicit collection at the very
    end, especially if most of the objects will stay resident.

    Two GCTogglers are already present in the ``gcutils`` module:

    - :data:`toggle_gc` simply turns off GC at context entrance, and
      re-enables at exit
    - :data:`toggle_gc_postcollect` does the same, but triggers an
      explicit collection after re-enabling.

    >>> with toggle_gc:
    ...     x = [object() for i in range(1000)]

    Between those two instances, the ``GCToggler`` type probably won't
    be used much directly, but is documented for inheritance purposes.
    Fc                     || _         d S Npostcollect)selfr#   s     r   __init__zGCToggler.__init__   s    &r   c                 ,    t          j                     d S r!   )r   disable)r$   s    r   	__enter__zGCToggler.__enter__   s    

r   c                 d    t          j                     | j        rt          j                     d S d S r!   )r   enabler#   collect)r$   exc_typeexc_valexc_tbs       r   __exit__zGCToggler.__exit__   s1    
	 	JLLLLL	 	r   N)F)__name__
__module____qualname____doc__r%   r(   r/   r	   r   r   r   r   }   sP         &' ' ' '      r   r   r"   )T)
r3   r   sys__all__r   builtin_module_names_IS_PYPYr   r   r   r	   r   r   <module>r8      s   > > 
			 




H
H
H0 0 0 0f 11        @ IKK	( "	d333 @ @r   