Beispiel #1
0
        def __wait_fdu(self, fdu_uuid):
            '''

            Function used to wait if an instance changest state
             (eg. configured -> run) or goes to error state

            :param node_uuid
            :param fdu_uuid
            :param state the new expected state

            :return dict {'status':<new status>,
                            'fdu_uuid':fdu_uuid}

            '''

            local_var = MVar()

            def cb(fdu_info):
                local_var.put(fdu_info)

            fdu_info = self.connector.glob.actual.get_fdu_info(
                self.sysid, self.tenantid, fdu_uuid)
            while fdu_info is None:
                fdu_info = self.connector.glob.actual.get_fdu_info(
                    self.sysid, self.tenantid, fdu_uuid)
            # while fdu_info is None:
            #     fdu_info = local_var.get()
            res = {'fdu_uuid': fdu_uuid}
            return res
Beispiel #2
0
    def test_get_put(self):
        def worker(var):
            time.sleep(randint(1, 3))
            var.put(1)

        def worker2(var):
            var.put(3)

        local_var = MVar()
        Thread(target=worker, args=(local_var, ), daemon=True).start()
        res = local_var.take()

        local_var.put(2)
        Thread(target=worker2, args=(local_var, ), daemon=True).start()
        res2 = local_var.take()
        res3 = local_var.take()

        self.assertEqual(res, 1)
        self.assertEqual(res2, 2)
        self.assertEqual(res3, 3)
Beispiel #3
0
import unittest
import time
from mvar import MVar
import zenoh

z1_sub1_mvar = MVar()
z2_sub1_mvar = MVar()
z1_sto1_last_res = None
z1_sto1_mvar = MVar()
z2_sto1_last_res = None
z2_sto1_mvar = MVar()
replies = []
replies_mvar = MVar()


def z1_sub1_listener(rname, data, info):
    z1_sub1_mvar.put((rname, data))


def z2_sub1_listener(rname, data, info):
    z2_sub1_mvar.put((rname, data))


def z1_sto1_listener(rname, data, info):
    global z1_sto1_last_res
    z1_sto1_last_res = (rname, (data, info))
    z1_sto1_mvar.put((rname, data))


def z2_sto1_listener(rname, data, info):
    global z2_sto1_last_res
Beispiel #4
0
import time
from threading import Thread
from random import randint
from mvar import MVar


def worker(var):
    time.sleep(randint(1, 3))
    var.put(1)


def worker2(var):
    var.put(3)


print('Starting Worker1 and waiting on MVar the result...')
local_var = MVar()
Thread(target=worker, args=(local_var, ), daemon=True).start()
res = local_var.take()
print("Worker1 returned {}".format(res))
print("Putting a value on the MVar to block Worker2")
local_var.put(2)
print('Starting Worker2...')
Thread(target=worker2, args=(local_var, ), daemon=True).start()
res2 = local_var.take()
print("Getting previous value stored in MVar to"
      "unlock Worker2 - MVar.take() returned {}".format(res2))
res3 = local_var.take()
print("Worker3 returned {}".format(res3))