Shortcuts

ManagerMixin

class mmengine.utils.ManagerMixin(name='', **kwargs)[source]

ManagerMixin is the base class for classes that have global access requirements.

The subclasses inheriting from ManagerMixin can get their global instances.

Examples

>>> class GlobalAccessible(ManagerMixin):
>>>     def __init__(self, name=''):
>>>         super().__init__(name)
>>>
>>> GlobalAccessible.get_instance('name')
>>> instance_1 = GlobalAccessible.get_instance('name')
>>> instance_2 = GlobalAccessible.get_instance('name')
>>> assert id(instance_1) == id(instance_2)
Parameters

name (str) – Name of the instance. Defaults to ‘’.

classmethod check_instance_created(name)[source]

Check whether the name corresponding instance exists.

Parameters

name (str) – Name of instance.

Returns

Whether the name corresponding instance exists.

Return type

bool

classmethod get_current_instance()[source]

Get latest created instance.

Before calling get_current_instance, The subclass must have called get_instance(xxx) at least once.

Examples
>>> instance = GlobalAccessible.get_current_instance()
AssertionError: At least one of name and current needs to be set
>>> instance = GlobalAccessible.get_instance('name1')
>>> instance.instance_name
name1
>>> instance = GlobalAccessible.get_current_instance()
>>> instance.instance_name
name1
Returns

Latest created instance.

Return type

object

classmethod get_instance(name, **kwargs)[source]

Get subclass instance by name if the name exists.

If corresponding name instance has not been created, get_instance will create an instance, otherwise get_instance will return the corresponding instance.

Examples
>>> instance1 = GlobalAccessible.get_instance('name1')
>>> # Create name1 instance.
>>> instance.instance_name
name1
>>> instance2 = GlobalAccessible.get_instance('name1')
>>> # Get name1 instance.
>>> assert id(instance1) == id(instance2)
Parameters

name (str) – Name of instance. Defaults to ‘’.

Returns

Corresponding name instance, the latest instance, or root instance.

Return type

object

property instance_name: str

Get the name of instance.

Returns

Name of instance.

Return type

str

Read the Docs v: v0.10.0
Versions
latest
stable
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.