當前位置: 首頁>>代碼示例>>Python>>正文


Python Thread.current方法代碼示例

本文整理匯總了Python中mo_threads.Thread.current方法的典型用法代碼示例。如果您正苦於以下問題:Python Thread.current方法的具體用法?Python Thread.current怎麽用?Python Thread.current使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mo_threads.Thread的用法示例。


在下文中一共展示了Thread.current方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: note

# 需要導入模塊: from mo_threads import Thread [as 別名]
# 或者: from mo_threads.Thread import current [as 別名]
    def note(
        cls,
        template,
        default_params={},
        stack_depth=0,
        log_context=None,
        **more_params
    ):
        """
        :param template: *string* human readable string with placeholders for parameters
        :param default_params: *dict* parameters to fill in template
        :param stack_depth:  *int* how many calls you want popped off the stack to report the *true* caller
        :param log_context: *dict* extra key:value pairs for your convenience
        :param more_params: *any more parameters (which will overwrite default_params)
        :return:
        """
        if not isinstance(template, text_type):
            Log.error("Log.note was expecting a unicode template")

        if len(template) > 10000:
            template = template[:10000]

        params = dict(unwrap(default_params), **more_params)

        log_params = set_default({
            "template": template,
            "params": params,
            "timestamp": datetime.utcnow(),
            "machine": machine_metadata
        }, log_context, {"context": exceptions.NOTE})

        if not template.startswith("\n") and template.find("\n") > -1:
            template = "\n" + template

        if cls.trace:
            log_template = "{{machine.name}} (pid {{machine.pid}}) - {{timestamp|datetime}} - {{thread.name}} - \"{{location.file}}:{{location.line}}\" ({{location.method}}) - " + template.replace("{{", "{{params.")
            f = sys._getframe(stack_depth + 1)
            log_params.location = {
                "line": f.f_lineno,
                "file": text_type(f.f_code.co_filename.split(os.sep)[-1]),
                "method": text_type(f.f_code.co_name)
            }
            thread = _Thread.current()
            log_params.thread = {"name": thread.name, "id": thread.id}
        else:
            log_template = "{{timestamp|datetime}} - " + template.replace("{{", "{{params.")

        cls.main_log.write(log_template, log_params)
開發者ID:rv404674,項目名稱:TUID,代碼行數:50,代碼來源:__init__.py

示例2: one_request

# 需要導入模塊: from mo_threads import Thread [as 別名]
# 或者: from mo_threads.Thread import current [as 別名]
def one_request(request, please_stop):
    and_op = request.where['and']

    files = []
    for a in and_op:
        if a['in'].path:
            files = a['in'].path
        elif a.eq.path:
            files = [a.eq.path]

    with Timer("Make TUID request from {{timestamp|datetime}}", {"timestamp": request.meta.request_time}):
        try:
            result = http.post_json(
                "http://localhost:5000/tuid",
                json=request,
                timeout=30
            )
            if result is None or len(result.data) != len(files):
                Log.note("incomplete response for {{thread}}", thread=Thread.current().name)
        except Exception as e:
            Log.warning("Request failure", cause=e)
開發者ID:rv404674,項目名稱:TUID,代碼行數:23,代碼來源:sqs_consumer.py

示例3: time_delta_pusher

# 需要導入模塊: from mo_threads import Thread [as 別名]
# 或者: from mo_threads.Thread import current [as 別名]
def time_delta_pusher(please_stop, appender, queue, interval):
    """
    appender - THE FUNCTION THAT ACCEPTS A STRING
    queue - FILLED WITH LOG ENTRIES {"template":template, "params":params} TO WRITE
    interval - timedelta
    USE IN A THREAD TO BATCH LOGS BY TIME INTERVAL
    """

    next_run = time() + interval

    while not please_stop:
        profiler = Thread.current().cprofiler
        profiler.disable()
        (Till(till=next_run) | please_stop).wait()
        profiler.enable()

        next_run = time() + interval
        logs = queue.pop_all()
        if not logs:
            continue

        lines = []
        for log in logs:
            try:
                if log is THREAD_STOP:
                    please_stop.go()
                    next_run = time()
                else:
                    expanded = expand_template(log.get("template"), log.get("params"))
                    lines.append(expanded)
            except Exception as e:
                location = log.get('params', {}).get('location', {})
                Log.warning("Trouble formatting log from {{location}}", location=location, cause=e)
                # SWALLOW ERROR, GOT TO KEEP RUNNING
        try:
            appender(u"\n".join(lines) + u"\n")
        except Exception as e:

            sys.stderr.write(str("Trouble with appender: ") + str(e.__class__.__name__) + str("\n"))
開發者ID:rv404674,項目名稱:TUID,代碼行數:41,代碼來源:log_usingThreadedStream.py

示例4: _annotate

# 需要導入模塊: from mo_threads import Thread [as 別名]
# 或者: from mo_threads.Thread import current [as 別名]
    def _annotate(
        cls,
        item,
        timestamp,
        stack_depth
    ):
        """
        :param itemt:  A LogItemTHE TYPE OF MESSAGE
        :param stack_depth: FOR TRACKING WHAT LINE THIS CAME FROM
        :return:
        """
        item.timestamp = timestamp
        item.machine = machine_metadata
        item.template = strings.limit(item.template, 10000)

        item.format = strings.limit(item.format, 10000)
        if item.format == None:
            format = text_type(item)
        else:
            format = item.format.replace("{{", "{{params.")
        if not format.startswith(CR) and format.find(CR) > -1:
            format = CR + format

        if cls.trace:
            log_format = item.format = "{{machine.name}} (pid {{machine.pid}}) - {{timestamp|datetime}} - {{thread.name}} - \"{{location.file}}:{{location.line}}\" - ({{location.method}}) - " + format
            f = sys._getframe(stack_depth + 1)
            item.location = {
                "line": f.f_lineno,
                "file": text_type(f.f_code.co_filename),
                "method": text_type(f.f_code.co_name)
            }
            thread = _Thread.current()
            item.thread = {"name": thread.name, "id": thread.id}
        else:
            log_format = item.format = "{{timestamp|datetime}} - " + format

        cls.main_log.write(log_format, item.__data__())
開發者ID:klahnakoski,項目名稱:pyLibrary,代碼行數:39,代碼來源:__init__.py


注:本文中的mo_threads.Thread.current方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。