def sim_process(sim_queue, client_queue): sim = Simulation('../model/Cirship.fmu') print('Simulation ready') id = 0 watches = { 'real': set(), 'bool': set(), } while True: while not client_queue.empty(): msg = client_queue.get_nowait() if msg['type'] == 'set': ref = msg['ref'] value = msg['value'] if isinstance(value, bool): sim.set_bool(ref, value) else: sim.set_real(ref, value) elif msg['type'] == 'watch': for ref in msg.get('real', []): watches['real'].add(ref) for ref in msg.get('bool', []): watches['bool'].add(ref) t = sim.update() id += 1 reals = {ref: sim.get_real(ref) for ref in watches['real']} bools = {ref: sim.get_bool(ref) for ref in watches['bool']} refs = {'id': id, 'time': t, **reals, **bools} sim_queue.put(refs) time.sleep(0.05)