text
stringlengths
0
828
objects generated by the given callable that can't be collected by Python's
usual reference-count based garbage collection.
This includes objects that will eventually be collected by the cyclic
garbage collector, as well as genuinely unreachable objects that will
never be collected.
`callable` should be a callable that takes no arguments; its return
value (if any) will be ignored.
""""""
with restore_gc_state():
gc.disable()
gc.collect()
gc.set_debug(gc.DEBUG_SAVEALL)
callable()
new_object_count = gc.collect()
if new_object_count:
objects = gc.garbage[-new_object_count:]
del gc.garbage[-new_object_count:]
else:
objects = []
return ObjectGraph(objects)"
1583,"def garbage():
""""""
Collect garbage and return an :class:`~refcycle.object_graph.ObjectGraph`
based on collected garbage.
The collected elements are removed from ``gc.garbage``, but are still kept
alive by the references in the graph. Deleting the
:class:`~refcycle.object_graph.ObjectGraph` instance and doing another
``gc.collect`` will remove those objects for good.
""""""
with restore_gc_state():
gc.disable()
gc.set_debug(gc.DEBUG_SAVEALL)
collected_count = gc.collect()
if collected_count:
objects = gc.garbage[-collected_count:]
del gc.garbage[-collected_count:]
else:
objects = []
return ObjectGraph(objects)"
1584,"def objects_reachable_from(obj):
""""""
Return graph of objects reachable from *obj* via ``gc.get_referrers``.
Returns an :class:`~refcycle.object_graph.ObjectGraph` object holding all
objects reachable from the given one by following the output of
``gc.get_referrers``. Note that unlike the
:func:`~refcycle.creators.snapshot` function, the output graph may
include non-gc-tracked objects.
""""""
# Depth-first search.
found = ObjectGraph.vertex_set()
to_process = [obj]
while to_process:
obj = to_process.pop()
found.add(obj)
for referent in gc.get_referents(obj):
if referent not in found:
to_process.append(referent)
return ObjectGraph(found)"
1585,"def snapshot():
""""""Return the graph of all currently gc-tracked objects.
Excludes the returned :class:`~refcycle.object_graph.ObjectGraph` and
objects owned by it.
Note that a subsequent call to :func:`~refcycle.creators.snapshot` will
capture all of the objects owned by this snapshot. The
:meth:`~refcycle.object_graph.ObjectGraph.owned_objects` method may be
helpful when excluding these objects from consideration.
""""""
all_objects = gc.get_objects()
this_frame = inspect.currentframe()
selected_objects = []
for obj in all_objects:
if obj is not this_frame:
selected_objects.append(obj)
graph = ObjectGraph(selected_objects)
del this_frame, all_objects, selected_objects, obj
return graph"
1586,"def extendMarkdown(self, md, md_globals):
""""""
Every extension requires a extendMarkdown method to tell the markdown
renderer how use the extension.
""""""
md.registerExtension(self)
for processor in (self.preprocessors or []):
md.preprocessors.add(processor.__name__.lower(), processor(md), '_end')
for pattern in (self.inlinepatterns or []):
md.inlinePatterns.add(pattern.__name__.lower(), pattern(md), '_end')
for processor in (self.postprocessors or []):