def prepare(self): # Maybe the brok is a old daemon one or was already prepared # if so, the data is already ok if hasattr(self, 'prepared') and not self.prepared: self.data = SafeUnpickler.loads(self.data) if hasattr(self, 'instance_id'): self.data['instance_id'] = self.instance_id self.prepared = True
def f_wrapper(): t0 = time.time() args_time = aqu_lock_time = calling_time = json_time = 0 need_lock = getattr(f, 'need_lock', True) # Warning : put the bottle.response set inside the wrapper # because outside it will break bottle d = {} method = getattr(f, 'method', 'get').lower() for aname in args: v = None if method == 'post': v = bottle.request.forms.get(aname, None) # Post args are zlibed and cPickled (but in # safemode) if v is not None: v = zlib.decompress(v) v = SafeUnpickler.loads(v) elif method == 'get': v = bottle.request.GET.get(aname, None) if v is None: # Maybe we got a default value? default_args = self.registered_fun_defaults.get(fname, {}) if aname not in default_args: raise Exception('Missing argument %s' % aname) v = default_args[aname] d[aname] = v t1 = time.time() args_time = t1 - t0 if need_lock: logger.debug("HTTP: calling lock for %s", fname) lock.acquire() t2 = time.time() aqu_lock_time = t2 - t1 try: ret = f(**d) # Always call the lock release if need finally: # Ok now we can release the lock if need_lock: lock.release() t3 = time.time() calling_time = t3 - t2 encode = getattr(f, 'encode', 'json').lower() j = json.dumps(ret) t4 = time.time() json_time = t4 - t3 global_time = t4 - t0 logger.debug("Debug perf: %s [args:%s] [aqu_lock:%s]" "[calling:%s] [json:%s] [global:%s]", fname, args_time, aqu_lock_time, calling_time, json_time, global_time) lst = [('args', args_time), ('aqulock', aqu_lock_time), ('calling', calling_time), ('json', json_time), ('global', global_time)] # increase the stats timers for (k, _t) in lst: statsmgr.timing('http.%s.%s' % (fname, k), _t, 'perf') return j
def f_wrapper(): t0 = time.time() args_time = aqu_lock_time = calling_time = json_time = 0 need_lock = getattr(f, 'need_lock', True) # Warning : put the bottle.response set inside the wrapper # because outside it will break bottle d = {} method = getattr(f, 'method', 'get').lower() for aname in args: v = None if method == 'post': v = bottle.request.forms.get(aname, None) # Post args are zlibed and cPickled (but in # safemode) if v is not None: v = zlib.decompress(v) v = SafeUnpickler.loads(v) elif method == 'get': v = bottle.request.GET.get(aname, None) if v is None: # Maybe we got a default value? default_args = self.registered_fun_defaults.get( fname, {}) if aname not in default_args: raise Exception('Missing argument %s' % aname) v = default_args[aname] d[aname] = v t1 = time.time() args_time = t1 - t0 if need_lock: logger.debug("HTTP: calling lock for %s", fname) lock.acquire() t2 = time.time() aqu_lock_time = t2 - t1 try: ret = f(**d) # Always call the lock release if need finally: # Ok now we can release the lock if need_lock: lock.release() t3 = time.time() calling_time = t3 - t2 encode = getattr(f, 'encode', 'json').lower() j = json.dumps(ret) t4 = time.time() json_time = t4 - t3 global_time = t4 - t0 logger.debug( "Debug perf: %s [args:%s] [aqu_lock:%s]" "[calling:%s] [json:%s] [global:%s]", fname, args_time, aqu_lock_time, calling_time, json_time, global_time) lst = [('args', args_time), ('aqulock', aqu_lock_time), ('calling', calling_time), ('json', json_time), ('global', global_time)] # increase the stats timers for (k, _t) in lst: statsmgr.timing('http.%s.%s' % (fname, k), _t, 'perf') logger.info( "[api]:{func}, [args]:{args} [cost]:{cost}".format( func=fname, args=json.dumps(d), cost=calling_time)) return j
def launch_safe_pickle(): SafeUnpickler.loads(buf)
def launch_safe_pickle(self, buf): SafeUnpickler.loads(buf)