Queued Services

What means ‘Queued’?

‘Queued’ means the service stores the function calls in a Queue and the execution order is according to their priorities.

Internally the commands are forwarded to a PriorityQueue, which is not process safe.

Using a separate result queue the return values are passed to the according callers.

_images/queued_service.png

How to define an object for queued access?

A QueuedService wraps a normal Service. The priority decorator is used to define priorities for the functions. Higher priorities lead to earlier execution. The default priority for not decorated functions is 0.

Example:

class ExampleService(object):

    @priority(5)
    def fast_operation(self):
        # do fast stuff

    @priority(10)
    def slow_operation(self):
        # do slow stuff

The following call sequence:

service.slow_operation()
service.fast_operation()
service.slow_operation()
service.fast_operation()
service.slow_operation()
service.fast_operation()

leads to an execution order of:

  1. slow_operation
  2. slow_operation
  3. slow_operation
  4. fast_operation
  5. fast_operation
  6. fast_operation

How to define a Queued Service?

Derive a class from QueuedService and add a CLASS property, which contains the class of the object to be wrapped.

Example:

class QueuedExampleService(QueuedService):

    CLASS = TestObject

Note

init_resources() and close_resources() are called on initialization and closing if provided by the wrapped object

Note

For an extensive example see Queued Service Example.

Callbacks and Events

Using callbacks does not differ from the normal use, but using Events does. It works to register() and unregister() as usual, but it is not possible to call trigger() remotely. This will cause a ForbiddenAttributeAccessError to be raised. (See Queued Callback Example)

Warning

It is not possible to wrap a CallbackObject or CallbackService or a subclass of them by a QueuedService!

Autoproxy

The Autoproxy feature is implemented for QueuedService, too. If an object that is wrapped by the QueuedService is passed to another process. It is replaced by a Proxy to the QueuedService

API Reference

@PyroMP.priority(prio)

Defines the priority for the decorated function.

Parameters :
prio : int

Desired priority

class PyroMP.QueuedService(async=True)

Bases: Service

Manages the whole queuing stuff for queued calls.

Table Of Contents

Previous topic

Callbacks

Next topic

QtService

This Page