def _log_method(self, context, args, kwargs): method = helpers.get_current_method(context) param_gen = itertools.chain( (six.text_type(arg) for arg in args), (u'{0} => {1}'.format(name, value) for name, value in six.iteritems(kwargs))) params_str = u', '.join(param_gen) method_name = '::'.join((method.declaring_type.name, method.name)) thread_id = helpers.get_current_thread_id() caller_str = '' caller_ctx = helpers.get_caller_context(context) if caller_ctx is not None: frame = stack_trace.compose_stack_frame(caller_ctx) if frame['location']: caller_str = ' called from ' + stack_trace.format_frame(frame) LOG.trace(u'{thread}: Begin execution {method}({params}){caller}' .format(thread=thread_id, method=method_name, params=params_str, caller=caller_str)) try: def log_result(result): LOG.trace( u'{thread}: End execution {method} with result ' u'{result}'.format( thread=thread_id, method=method_name, result=result)) yield log_result except Exception as e: LOG.trace( u'{thread}: End execution {method} with exception ' u'{exc}'.format(thread=thread_id, method=method_name, exc=e)) raise
def _acquire_method_lock(self, method, this): method_id = id(method) if method.is_static: this_id = id(method.declaring_type) else: this_id = this.object_id thread_id = helpers.get_current_thread_id() while True: event, event_owner = self._locks.get( (method_id, this_id), (None, None)) if event: if event_owner == thread_id: event = None break else: event.wait() else: event = eventlet.event.Event() self._locks[(method_id, this_id)] = (event, thread_id) break try: yield finally: if event is not None: del self._locks[(method_id, this_id)] event.send()
def _acquire_method_lock(self, method, this): method_id = id(method) if method.is_static: this_id = id(method.declaring_type) else: this_id = this.object_id thread_id = helpers.get_current_thread_id() while True: event, event_owner = self._locks.get((method_id, this_id), (None, None)) if event: if event_owner == thread_id: event = None break else: event.wait() else: event = eventlet.event.Event() self._locks[(method_id, this_id)] = (event, thread_id) break try: yield finally: if event is not None: del self._locks[(method_id, this_id)] event.send()
def _log_method(self, context, args, kwargs): method = helpers.get_current_method(context) param_gen = itertools.chain( (six.text_type(arg) for arg in args), (u'{0} => {1}'.format(name, value) for name, value in kwargs.items())) params_str = u', '.join(param_gen) method_name = '::'.join((method.declaring_type.name, method.name)) thread_id = helpers.get_current_thread_id() caller_str = '' caller_ctx = helpers.get_caller_context(context) if caller_ctx is not None: frame = stack_trace.compose_stack_frame(caller_ctx) if frame['location']: caller_str = ' called from ' + stack_trace.format_frame(frame) LOG.trace(u'{thread}: Begin execution {method}({params}){caller}' .format(thread=thread_id, method=method_name, params=params_str, caller=caller_str)) try: def log_result(result): LOG.trace( u'{thread}: End execution {method} with result ' u'{result}'.format( thread=thread_id, method=method_name, result=result)) yield log_result except Exception as e: LOG.trace( u'{thread}: End execution {method} with exception ' u'{exc}'.format(thread=thread_id, method=method_name, exc=e)) raise
def _acquire_method_lock(self, func, this): method_id = id(func) if isinstance(this, dsl_types.MuranoClass): this_id = id(this) else: this_id = this.object_id thread_id = helpers.get_current_thread_id() while True: event, event_owner = self._locks.get( (method_id, this_id), (None, None)) if event: if event_owner == thread_id: event = None break else: event.wait() else: event = eventlet.event.Event() self._locks[(method_id, this_id)] = (event, thread_id) break try: yield finally: if event is not None: del self._locks[(method_id, this_id)] event.send()
def _log_method(self, context, args, kwargs): method = helpers.get_current_method(context) param_gen = itertools.chain( (six.text_type(arg) for arg in args), (u"{0} => {1}".format(name, value) for name, value in six.iteritems(kwargs)), ) params_str = u", ".join(param_gen) method_name = "{0}::{1}".format(method.murano_class.name, method.name) thread_id = helpers.get_current_thread_id() caller_str = "" caller_ctx = helpers.get_caller_context(context) if caller_ctx is not None: frame = stack_trace.compose_stack_frame(caller_ctx) if frame["location"]: caller_str = " called from " + stack_trace.format_frame(frame) LOG.trace( u"{thread}: Begin execution {method}({params}){caller}".format( thread=thread_id, method=method_name, params=params_str, caller=caller_str ) ) try: def log_result(result): LOG.trace( u"{thread}: End execution {method} with result " u"{result}".format(thread=thread_id, method=method_name, result=result) ) yield log_result except Exception as e: LOG.trace( u"{thread}: End execution {method} with exception " u"{exc}".format(thread=thread_id, method=method_name, exc=e) ) raise
def _acquire_method_lock(self, method, this, arg_val_dict): if this is None: if not arg_val_dict: # if neither "this" nor argument values are set then no # locking is needed key = None else: # if only the argument values are passed then find the lock # list only by the method key = (None, id(method)) else: if method.is_static: # find the lock list by the type and method key = (id(method.declaring_type), id(method)) else: # find the lock list by the object and method key = (this.object_id, id(method)) thread_id = helpers.get_current_thread_id() while True: event, event_owner = None, None if key is None: # no locking needed break lock_list = self._locks.setdefault(key, []) # lock list contains a list of tuples: # first item of each tuple is a dict with the values of locking # arguments (it is used for argument values comparison), # second item is an event to wait on, # third one is the owner thread id # If this lock list is empty it means no locks on this object and # method at all. for arg_vals, l_event, l_event_owner in lock_list: if arg_vals == arg_val_dict: event = l_event event_owner = l_event_owner break if event: if event_owner == thread_id: # this means a re-entrant lock: the tuple with the same # value of the first element exists in the list, but it was # acquired by the same green thread. We may proceed with # the call in this case event = None break else: event.wait() else: # this means either the lock list was empty or didn't contain a # tuple with the first element equal to arg_val_dict. # Then let's acquire a lock, i.e. create a new tuple and place # it into the list event = eventlet.event.Event() event_owner = thread_id lock_list.append((arg_val_dict, event, event_owner)) break try: yield finally: if event is not None: lock_list.remove((arg_val_dict, event, event_owner)) if len(lock_list) == 0: del self._locks[key] event.send()