Skip to content

Commit 75a567d

Browse files
add to doc
1 parent 7f0cd0b commit 75a567d

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

doc/debug.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: pytools.debug

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Welcome to pytools's documentation!
99
obj_array
1010
persistent_dict
1111
graph
12+
debug
1213
tag
1314
codegen
1415
mpi

pytools/debug.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
__license__ = """
2+
Permission is hereby granted, free of charge, to any person obtaining a copy
3+
of this software and associated documentation files (the "Software"), to deal
4+
in the Software without restriction, including without limitation the rights
5+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
copies of the Software, and to permit persons to whom the Software is
7+
furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in
10+
all copies or substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
THE SOFTWARE.
19+
"""
20+
21+
22+
__doc__ = """
23+
Debugging helpers
24+
=================
25+
26+
.. autofunction:: make_unique_filesystem_object
27+
.. autofunction:: open_unique_debug_file
28+
.. autofunction:: refdebug
29+
.. autofunction:: get_object_cycles
30+
.. autofunction:: estimate_memory_usage
31+
32+
"""
33+
134
import sys
235
from typing import Collection, List, Set
336

@@ -142,13 +175,28 @@ def is_excluded(o):
142175

143176
# {{{ Find circular references
144177

145-
# https://code.activestate.com/recipes/523004-find-cyclical-references/
178+
# Based on https://code.activestate.com/recipes/523004-find-cyclical-references/
146179

147180
def get_object_cycles(objects: Collection[object]) -> List[List[object]]:
148181
"""
149-
:param objects: A collection of objects to find cycles in. It is often
150-
useful to pass in gc.garbage to find the cycles that are preventing some
151-
objects from being garbage collected.
182+
Find circular references in *objects*. This can be useful for example to debug
183+
why certain objects need to be freed via garbage collection instead of
184+
reference counting.
185+
186+
:arg objects: A collection of objects to find cycles in. A potential way
187+
to find a list of objects potentially containing cycles from the garbage
188+
collector is the following code::
189+
190+
gc.set_debug(gc.DEBUG_SAVEALL)
191+
gc.collect()
192+
gc.set_debug(0)
193+
obj_list = gc.garbage
194+
195+
from pytools.debug import get_object_cycles
196+
print(get_object_cycles(obj_list))
197+
198+
:returns: A :class:`list` in which each element contains a :class:`list`
199+
of objects forming a cycle.
152200
"""
153201
def recurse(obj: object, start: object, all_objs: Set[object],
154202
current_path: List[object]) -> None:

0 commit comments

Comments
 (0)