本文整理汇总了Python中brian2.core.names.Nameable.__instances__方法的典型用法代码示例。如果您正苦于以下问题:Python Nameable.__instances__方法的具体用法?Python Nameable.__instances__怎么用?Python Nameable.__instances__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brian2.core.names.Nameable
的用法示例。
在下文中一共展示了Nameable.__instances__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear
# 需要导入模块: from brian2.core.names import Nameable [as 别名]
# 或者: from brian2.core.names.Nameable import __instances__ [as 别名]
def clear(erase=False):
'''
Stops all Brian objects from being automatically detected
Stops objects from being tracked by `run` and `reinit`.
Use this if you are seeing `MagicError` on repeated runs.
Parameters
----------
erase : bool, optional
If set to ``True``, all data attributes of all Brian objects
will be set to ``None``. This
can help solve problems with circular references stopping objects
from being garbage collected, and is a quick way to ensure that all
memory associated to Brian objects is deleted.
Notes
-----
Removes the objects from ``BrianObject.__instances__()`` and
``Nameable.__instances__()``.
Will also set the
`BrianObject.active` flag to ``False`` for already existing `Network`
objects. Calls a garbage collection on completion.
See ALso
--------
run, reinit, MagicError
'''
if erase:
instances = set(BrianObject.__instances__())
for obj in instances:
obj = obj()
if obj is None:
continue
for k, v in obj.__dict__.iteritems():
object.__setattr__(obj, k, None)
BrianObject.__instances__().clear()
Nameable.__instances__().clear()
gc.collect()