text stringlengths 0 828 |
|---|
# add the request time to the log_dict; if no start time is |
# available, use -1 as NA value |
request_time = ( |
time.time() - self.start_time if hasattr(self, 'start_time') |
and self.start_time else -1) |
log_dict.update({'request_time': request_time}) |
is_request_time_too_high = ( |
request_time > float(settings.LOGUTILS_REQUEST_TIME_THRESHOLD)) |
use_sql_info = settings.DEBUG or is_request_time_too_high |
log_msg = create_log_message(log_dict, use_sql_info, fmt=False) |
if is_request_time_too_high: |
logger.warning(log_msg, log_dict, extra=log_dict) |
else: |
logger.info(log_msg, log_dict, extra=log_dict) |
except Exception as e: |
logger.exception(e) |
return response" |
431,"def synchronized(obj): |
"""""" |
This function has two purposes: |
1. Decorate a function that automatically synchronizes access to the object |
passed as the first argument (usually `self`, for member methods) |
2. Synchronize access to the object, used in a `with`-statement. |
Note that you can use #wait(), #notify() and #notify_all() only on |
synchronized objects. |
# Example |
```python |
class Box(Synchronizable): |
def __init__(self): |
self.value = None |
@synchronized |
def get(self): |
return self.value |
@synchronized |
def set(self, value): |
self.value = value |
box = Box() |
box.set('foobar') |
with synchronized(box): |
box.value = 'taz\'dingo' |
print(box.get()) |
``` |
# Arguments |
obj (Synchronizable, function): The object to synchronize access to, or a |
function to decorate. |
# Returns |
1. The decorated function. |
2. The value of `obj.synchronizable_condition`, which should implement the |
context-manager interface (to be used in a `with`-statement). |
"""""" |
if hasattr(obj, 'synchronizable_condition'): |
return obj.synchronizable_condition |
elif callable(obj): |
@functools.wraps(obj) |
def wrapper(self, *args, **kwargs): |
with self.synchronizable_condition: |
return obj(self, *args, **kwargs) |
return wrapper |
else: |
raise TypeError('expected Synchronizable instance or callable to decorate')" |
432,"def wait(obj, timeout=None): |
"""""" |
Wait until *obj* gets notified with #notify() or #notify_all(). If a timeout |
is specified, the function can return without the object being notified if |
the time runs out. |
Note that you can only use this function on #synchronized() objects. |
# Arguments |
obj (Synchronizable): An object that can be synchronized. |
timeout (number, None): The number of seconds to wait for the object to get |
notified before returning. If not value or the value #None is specified, |
the function will wait indefinetily. |
"""""" |
if timeout is None: |
return obj.synchronizable_condition.wait() |
else: |
return obj.synchronizable_condition.wait(timeout)" |
433,"def wait_for_condition(obj, cond, timeout=None): |
"""""" |
This is an extended version of #wait() that applies the function *cond* to |
check for a condition to break free from waiting on *obj*. Note that *obj* |
must be notified when its state changes in order to check the condition. |
Note that access to *obj* is synchronized when *cond* is called. |
# Arguments |
obj (Synchronizable): The object to synchronize and wait for *cond*. |
cond (function): A function that accepts *obj* as an argument. Must return |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.