scistag.remotestag.service.RemoteService

class RemoteService(identifier, multithreading=True)[source]

Bases: object

Defines a service hosted on this machine. A service consists of one or multiple services sharing the same data.

Parameters
  • identifier (str) –

    The service’s unique identifier in the form com.company.ai.inference.yolov2.

    A service’s name is not allowed to be contained within another service’s name.

  • multithreading (bool) – Defines if this data can be accessed from multiple threads or is using thread local data (such as many ML libraries).

Methods

deinitialize

Overwrite this method with your deinitialization code.

get_identifier

Returns the service's identifier

get_single_threaded

Returns True if this service does NOT support multithreading and needs it's own worker thread

initialize

Overwrite this method with your initialization code.

provides_function

Returns if the function is known

register_callback

Registers a new function.

register_function

Registers a new function.

run_task

Executes a task

unwrap

Unwraps a potentially single value result

Attributes

INPUT_VALUE

Key for single input value in the parameter dictionary

RESULT_VALUE

Key for the result value in the dictionary

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

_identifier

The service's identifier

_multithreading

Defines if the service is multithreading capable

_functions

Set of all registered functions

_lock

Data access lock

_started

Defines the service was already stared

deinitialize()[source]

Overwrite this method with your deinitialization code.

If this service is thread bound it’s guaranteed to be executed on the execution thread.

get_identifier()[source]

Returns the service’s identifier

Return type

str

Returns

The identifier string

get_single_threaded()[source]

Returns True if this service does NOT support multithreading and needs it’s own worker thread

Return type

bool

Returns

True if not multithreading capable

initialize()[source]

Overwrite this method with your initialization code.

If this service is thread bound it’s guaranteed to be executed on the

later execution thread.

provides_function(identifier)[source]

Returns if the function is known

Parameters

identifier (str) – The function identifier

Return type

bool

Returns

True on success

register_callback(name, callback)[source]

Registers a new function. Functions can only be registered before the service was started.

Parameters
  • name (str) – The function’s name

  • callback (Callable[[dict], dict]) – The callback function to be called

Return True on success

Return type

bool

register_function(function)[source]

Registers a new function. Functions can only be registered before the service was started.

Parameters

function (RemoteFunction) – The function to register

Return True on success

Return type

bool

run_task(function_name, parameters, unwrap=False)[source]

Executes a task

Parameters
  • function_name (str) – The function’s name

  • parameters (Union[dict, str, float, bool, int, bytes]) – The function’s parameters. Either as base type for a single parameter or as dictionary

  • unwrap – Defines if a single value result shall not be wrapped into a dictionary

Return type

Union[dict, str, float, bool, int, bytes]

Returns

The function’s results

classmethod unwrap(result)[source]

Unwraps a potentially single value result

Parameters

result (dict) – The original function result

Return type

Union[dict, str, float, bool, int, bytes]

Returns

The single value if there is just one element, otherwise the dictionary

INPUT_VALUE = '_value'

Key for single input value in the parameter dictionary

RESULT_VALUE = '_resultValue'

Key for the result value in the dictionary

_functions: dict[str, Union[scistag.remotestag.service_function.RemoteFunction, Callable[[dict], dict]]]

Set of all registered functions

_identifier

The service’s identifier

_lock

Data access lock

_multithreading

Defines if the service is multithreading capable

_started

Defines the service was already stared