lclib.proxydevice

Proxy Device: decorators that expose a class and chose methods/properties through network, using RpyC backend for communication.

Example code:

@proxydevice(address=("127.0.0.1", 5055))
class A:
    def __init__(self, x=1):
        self.x = x
        self.a = "abc"
        self.stop = False

    # A non-exposed call
    def do_something(self, y):
        self.x += y

    # An exposed call
    @proxycall()
    def get_multiple(self, y):
        return self.x * y

    # An exposed call allowed only for the client with admin rights
    @proxycall(admin=True)
    def set_a(self, a):
        self.a = a

    # A long task. Must be made non-blocking otherwise the sever will wait for return value
    @proxycall(admin=True, block=False)
    def long_task(self):
        for i in range(10):
            print(chr(i + 65))
            time.sleep(1)
            if self.stop:
                self.stop = False
                break
        return 1

    # Declaring the abort call, to be sent when ctrl-C is hit during a long call.
    @proxycall(interrupt=True)
    def abort(self):
        print("Aborting the long call!")
        self.stop = True

    # An exposed property
    @proxycall()
    @property
    def x_value(self):
        return self.x

    @x_value.setter
    def x_value(self, v):
        self.x = v

Create a normal instance:

a = A()

Or on one computer:

server = A.Server()

On another computer:

a = A.Client()
# now a has all methods that have been exposed by the proxycall decorator
a.get_multiple(5)
 -> 5

This file is part of lab-control-lib (c) 2023-2024 Pierre Thibault (pthibault@units.it)

Functions:

exception lclib.proxydevice.ProxyDeviceError[source]

Bases: Exception

class lclib.proxydevice.proxycall(admin=False, block=True, interrupt=False, **kwargs)[source]

Bases: object

Decorator to tag a method or property to be exposed for remote access.

class lclib.proxydevice.proxydevice(address=None, clean=True, stream=True, **kwargs)[source]

Bases: object

Decorator that does the main magic.