예제 #1
0
def _get_queues():
    queues = utils.get_thread_local(_THREAD_LOCAL_NAME)

    if queues is None:
        raise RuntimeError(
            'Operation queue is not initialized for the current thread.'
            ' Most likely some engine method is not decorated with'
            ' operation_queue.run()')

    return queues
예제 #2
0
def log_to_file(info, context=None):
    attrs = [
        str(info['timestamp']),
        info['base_id'],
        info['parent_id'],
        info['trace_id'],
        info['name']
    ]

    th_local_name = '_profiler_trace_%s_start_time_' % info['trace_id']

    if info['name'].endswith('-start'):
        utils.set_thread_local(
            th_local_name,
            datetime.datetime.utcnow()
        )

        # Insert a blank sequence for a trace start.
        attrs.insert(1, ' ' * 8)

    if info['name'].endswith('-stop'):
        delta = (
            datetime.datetime.utcnow() - utils.get_thread_local(th_local_name)
        ).total_seconds()

        utils.set_thread_local(th_local_name, None)

        # Insert a blank sequence for a trace start.
        attrs.insert(1, str(delta))

        if delta > 0.5:
            attrs.append(' <- !!!')

    if 'info' in info and 'db' in info['info']:
        db_info = copy.deepcopy(info['info']['db'])

        db_info['params'] = {
            k: str(v) if isinstance(v, datetime.datetime) else v
            for k, v in db_info.get('params', {}).items()
        }

        attrs.append(json.dumps(db_info))

    PROFILER_LOG.info(' '.join(attrs))
예제 #3
0
파일: base.py 프로젝트: shubhamdang/mistral
def get_tx_scoped_cache():
    return utils.get_thread_local(_TX_SCOPED_CACHE_THREAD_LOCAL_NAME)
예제 #4
0
파일: base.py 프로젝트: shubhamdang/mistral
def _get_thread_local_session():
    return utils.get_thread_local(_DB_SESSION_THREAD_LOCAL_NAME)
예제 #5
0
def ctx():
    if not has_ctx():
        raise exc.ApplicationContextNotFoundException()

    return utils.get_thread_local(_CTX_THREAD_LOCAL_NAME)