ManagerMixin — mmengine 0.10.7 documentation (original) (raw)

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 calledget_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_instancewill 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