| 1 | # replace PseuodbondGroup __init__ to allow tracking via weak refs
|
|---|
| 2 |
|
|---|
| 3 | _weak_refs = []
|
|---|
| 4 | def replacement__init__(self, *args, **kw):
|
|---|
| 5 | self._orig__init__(*args, **kw)
|
|---|
| 6 | from weakref import ref
|
|---|
| 7 | _weak_refs.append(ref(self))
|
|---|
| 8 |
|
|---|
| 9 | from chimerax.atomic import PseudobondGroup
|
|---|
| 10 | PseudobondGroup._orig__init__ = PseudobondGroup.__init__
|
|---|
| 11 | PseudobondGroup.__init__ = replacement__init__
|
|---|
| 12 |
|
|---|
| 13 | from chimerax.core.commands import run
|
|---|
| 14 | run(session, "open 7azs")
|
|---|
| 15 | run(session, "close")
|
|---|
| 16 | import gc
|
|---|
| 17 | gc.collect()
|
|---|
| 18 | import sys
|
|---|
| 19 | alive = [x for x in _weak_refs if x() is not None]
|
|---|
| 20 | print("before wait", len(alive), "live refs:", [(x(), "%d refs" % sys.getrefcount(x())) for x in alive])
|
|---|
| 21 | if len(alive) > 0:
|
|---|
| 22 | print("Referrers to first entry:")
|
|---|
| 23 | print(gc.get_referrers(alive[0]()))
|
|---|
| 24 | run(session, "wait 1")
|
|---|
| 25 | alive = [x for x in _weak_refs if x() is not None]
|
|---|
| 26 | print("after wait", len(alive), "live refs:", [x() for x in alive])
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|