def __init__(self, polled_call, polled_call_args=(), polling_period=1000, value_changed_callback=None, error_callback=None, compare=True): self.polled_call_ref = saferef.safe_ref(polled_call) self.args = polled_call_args self.polling_period = polling_period self.value_changed_callback_ref = saferef.safe_ref( value_changed_callback) self.error_callback_ref = saferef.safe_ref(error_callback) self.compare = compare self.old_res = NotInitializedValue self.queue = _threading.Queue() # Queue.Queue() self.delay = 0 self.stop_event = _threading.Event() self.async_watcher = gevent.get_hub().loop. async ()
def deal_with_job(req, args, kwargs): def run(req, fn, args, kwargs): try: result = fn(*args, **kwargs) except: exception, error_string, tb = sys.exc_info() result = CallException(exception, error_string, tb) req.set_result(result) if req.method == "new": klass = args[0] args = args[1:] try: new_obj = klass(*args, **kwargs) except: exception, error_string, tb = sys.exc_info() result = CallException(exception, error_string, tb) req.set_result(result) return queue = _threading.Queue() watcher = gevent.get_hub().loop. async () watcher.start(functools.partial(read_from_queue, queue)) objs[id(new_obj)] = { "queue": queue, "watcher": watcher, "obj": new_obj } req.set_result(new_obj) elif req.method == "exit": req.set_result(stop_event.set()) elif callable(req.method): run(req, req.method, args, kwargs) else: obj = objs[req.obj_id]["obj"] try: prop = getattr(obj.__class__, req.method) except AttributeError: pass else: if isinstance(prop, property): if args: # must be setter run(req, prop.fset, [obj] + list(args), kwargs) else: run(req, prop.fget, [obj], kwargs) return try: method = getattr(obj, req.method) except AttributeError: exception, error_string, tb = sys.exc_info() result = CallException(exception, error_string, tb) req.set_result(result) else: if callable(method): # method run(req, method, args, kwargs) else: # attribute if args: # write setattr(obj, req.method, args[0]) req.set_result(None) else: # read req.set_result(method)
# # This file is part of the bliss project # # Copyright (c) 2016 Beamline Control Unit, ESRF # Distributed under the GNU LGPLv3. See LICENSE for more info. '''Helpers to make TANGO_ & gevent_ work together''' from gevent import _threading import threading import gevent.event import sys import atexit import gevent import functools main_queue = _threading.Queue() gevent_thread_lock = _threading.Lock() gevent_thread_started = _threading.Event() gevent_thread = None GEVENT_THREAD_ID = None read_event_watcher = None objs = {} stop_event = gevent.event.Event() if not hasattr(gevent, "wait"): def gevent_wait(timeout=None): return gevent.run(timeout) gevent.wait = gevent_wait