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


Python sys._current_frames方法代碼示例

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


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

示例1: worker_int

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def worker_int(worker):
    worker.log.info("worker received INT or QUIT signal")

    # get traceback info
    import threading
    import sys
    import traceback

    id2name = {th.ident: th.name for th in threading.enumerate()}
    code = []
    for threadId, stack in list(sys._current_frames().items()):
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId, ""), threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    worker.log.debug("\n".join(code)) 
開發者ID:archesproject,項目名稱:arches,代碼行數:19,代碼來源:gunicorn_config.py

示例2: on_timeout

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def on_timeout():
    logger.debug("cli timeout ")
    # Timeout should have been handled by the orchestrator, if the cli timeout
    # has been reached, something is probably wrong : dump threads.
    for th in threading.enumerate():
        print(th)
        traceback.print_stack(sys._current_frames()[th.ident])
        print()

    if orchestrator is None:
        logger.debug("cli timeout with no orchestrator ?")
        return
    global timeout_stopped
    timeout_stopped = True

    orchestrator.stop_agents(20)
    orchestrator.stop()
    _results("TIMEOUT")
    sys.exit(0) 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:21,代碼來源:orchestrator.py

示例3: on_timeout

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def on_timeout():
    logger.debug("cli timeout ")
    # Timeout should have been handled by the orchestrator, if the cli timeout
    # has been reached, something is probably wrong : dump threads.
    for th in threading.enumerate():
        print(th)
        traceback.print_stack(sys._current_frames()[th.ident])
        print()

    if orchestrator is None:
        logger.debug("cli timeout with no orchestrator ?")
        return
    global timeout_stopped
    timeout_stopped = True
    # Stopping agents can be rather long, we need a big timeout !
    logger.debug("stop agent on cli timeout ")
    orchestrator.stop_agents(20)
    logger.debug("stop orchestrator on cli timeout ")
    orchestrator.stop()
    _results("TIMEOUT")
    # sys.exit(0)
    os._exit(2) 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:24,代碼來源:solve.py

示例4: on_timeout

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def on_timeout():
    if orchestrator is None:
        return
    # Timeout should have been handled by the orchestrator, if the cli timeout
    # has been reached, something is probably wrong : dump threads.
    for th in threading.enumerate():
        print(th)
        traceback.print_stack(sys._current_frames()[th.ident])
        print()
    if orchestrator is None:
        logger.debug("cli timeout with no orchestrator ?")
        return
    global timeout_stopped
    timeout_stopped = True

    # Stopping agents can be rather long, we need a big timeout !
    orchestrator.stop_agents(20)
    orchestrator.stop()
    _results("TIMEOUT")
    sys.exit(0) 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:22,代碼來源:run.py

示例5: on_timeout

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def on_timeout():
    global result, output_file
    global start_t
    duration = time.time() - start_t

    print("TIMEOUT when distributing")
    logger.info("cli timeout when distributing")
    for th in threading.enumerate():
        print(th)
        traceback.print_stack(sys._current_frames()[th.ident])

    result["status"] =  "TIMEOUT"
    result["inputs"]["duration"] = duration

    if output_file is not None:
        with open(output_file, encoding="utf-8", mode="w") as fo:
            fo.write(yaml.dump(result))
    print(yaml.dump(result))

    #os._exit(0)
    sys.exit(0) 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:23,代碼來源:distribute.py

示例6: thread_stacktraces

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def thread_stacktraces():
  """
  Provides a dump of the stacktrace information for all active threads.

  :returns: **dict** that maps thread names to their stacktrace
  """

  stacktraces = {}

  for thread in threading.enumerate():
    frame = sys._current_frames().get(thread.ident, None)

    if frame:
      stacktraces[thread.name] = ''.join(traceback.format_stack(frame))
    else:
      stacktraces[thread.name] = 'No traceback available'

  return stacktraces 
開發者ID:torproject,項目名稱:stem,代碼行數:20,代碼來源:output.py

示例7: _debug_current_process

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def _debug_current_process(sig, current_frame):
    """Interrupt running process, and provide a python prompt for interactive debugging.
    This code is based on http://stackoverflow.com/a/133384/396730
    """
    # Import modules only if necessary, readline is for shell history support.
    import code, traceback, readline, threading  # noqa: E401, F401 @UnresolvedImport @UnusedImport

    d = {"_frame": current_frame}  # Allow access to frame object.
    d.update(current_frame.f_globals)  # Unless shadowed by global
    d.update(current_frame.f_locals)

    i = code.InteractiveConsole(d)
    message = "Signal received : entering python shell.\n"

    threads = {thread.ident: thread for thread in threading.enumerate()}
    current_thread = threading.current_thread()
    for thread_id, frame in sys._current_frames().items():
        if current_thread.ident != thread_id:
            message += "\nTraceback of thread {}:\n".format(threads[thread_id])
            message += "".join(traceback.format_stack(frame))
    message += "\nTraceback of current thread {}:\n".format(current_thread)
    message += "".join(traceback.format_stack(current_frame))
    i.interact(message) 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:25,代碼來源:util.py

示例8: worker_int

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def worker_int(worker):
    worker.log.info("worker received INT or QUIT signal")

    ## get traceback info
    import threading, sys, traceback

    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId, ""),
                                            threadId))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename,
                                                        lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    worker.log.debug("\n".join(code)) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:19,代碼來源:gunicorn.conf.py

示例9: _current_frames

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def _current_frames():
            as_array = thread_states.entrySet().toArray()
            ret = {}
            for thread_to_state in as_array:
                thread = thread_to_state.getKey()
                if thread is None:
                    continue
                thread_state = thread_to_state.getValue()
                if thread_state is None:
                    continue

                frame = thread_state.frame
                if frame is None:
                    continue

                ret[thread.getId()] = frame
            return ret 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:19,代碼來源:pydevd_additional_thread_info_regular.py

示例10: sigquit_handler

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def sigquit_handler(sig, frame):  # pylint: disable=unused-argument
    """
    Helps debug deadlocks by printing stacktraces when this gets a SIGQUIT
    e.g. kill -s QUIT <PID> or CTRL+\
    """
    print("Dumping stack traces for all threads in PID {}".format(os.getpid()))
    id_to_name = {th.ident: th.name for th in threading.enumerate()}
    code = []
    for thread_id, stack in sys._current_frames().items():  # pylint: disable=protected-access
        code.append("\n# Thread: {}({})"
                    .format(id_to_name.get(thread_id, ""), thread_id))
        for filename, line_number, name, line in traceback.extract_stack(stack):
            code.append('File: "{}", line {}, in {}'
                        .format(filename, line_number, name))
            if line:
                code.append("  {}".format(line.strip()))
    print("\n".join(code)) 
開發者ID:apache,項目名稱:airflow,代碼行數:19,代碼來源:cli.py

示例11: inspect_threads

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def inspect_threads(thread_names=[]):
    """inspect_threads() -> {thread_name: {"locals": {}, "stack": ""}} : return threads' locals and stack"""
    import threading
    import sys
    import traceback
    pylane_thread_name = "pylane-shell-thread"
    stacks = {}
    frames = sys._current_frames()
    threads = threading.enumerate()
    for thread in threads:
        if thread.name == pylane_thread_name:
            continue
        if thread_names and thread.name not in thread_names:
            continue
        frame = frames.get(thread.ident)
        stack = ''.join(traceback.format_stack(frame)) if frame else ''
        stacks[thread.name] = {
            "locals": frame.f_locals,
            "stack": stack
        }
    return stacks 
開發者ID:NtesEyes,項目名稱:pylane,代碼行數:23,代碼來源:help_functions.py

示例12: LogThreadStack

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def LogThreadStack(thread, error_log_func=logging.critical):
  """Log the stack for the given thread.

  Args:
    thread: a threading.Thread instance.
    error_log_func: Logging function when logging errors.
  """
  stack = sys._current_frames()[thread.ident]
  error_log_func('*' * 80)
  error_log_func('Stack dump for thread %r', thread.name)
  error_log_func('*' * 80)
  for filename, lineno, name, line in traceback.extract_stack(stack):
    error_log_func('File: "%s", line %d, in %s', filename, lineno, name)
    if line:
      error_log_func('  %s', line.strip())
  error_log_func('*' * 80) 
開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:18,代碼來源:reraiser_thread.py

示例13: test_clear_threads_states_after_fork

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def test_clear_threads_states_after_fork(self):
        # Issue #17094: check that threads states are cleared after fork()

        # start a bunch of threads
        threads = []
        for i in range(16):
            t = threading.Thread(target=lambda : time.sleep(0.3))
            threads.append(t)
            t.start()

        pid = os.fork()
        if pid == 0:
            # check that threads states have been cleared
            if len(sys._current_frames()) == 1:
                os._exit(0)
            else:
                os._exit(1)
        else:
            _, status = os.waitpid(pid, 0)
            self.assertEqual(0, status)

        for t in threads:
            t.join() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:test_threading.py

示例14: dump_all_stacks

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def dump_all_stacks():
    """dump a stack trace for all running threads for debugging purpose"""

    def get_name(thread_id):
        """return the human readable name that was assigned to a thread"""
        for thread in threading.enumerate():
            if thread.ident == thread_id:
                return thread.name

    ret = "\n# Full stack trace of all running threads:\n"
    for thread_id, stack in sys._current_frames().items():
        ret += "\n# %s (%s)\n" % (get_name(thread_id), thread_id)
        for filename, lineno, name, line in traceback.extract_stack(stack):
            ret += 'File: "%s", line %d, in %s\n' % (filename, lineno, name)
            if line:
                ret += "  %s\n" % (line.strip())
    return ret 
開發者ID:caktux,項目名稱:pytrader,代碼行數:19,代碼來源:pytrader.py

示例15: process_sample

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import _current_frames [as 別名]
def process_sample(self, signal_frame, sample_time, main_thread_id):
        if self.profile:
            start = time.clock()

            current_frames = sys._current_frames()
            items = current_frames.items()
            for thread_id, thread_frame in items:
                if thread_id == main_thread_id:
                    thread_frame = signal_frame

                stack = self.recover_stack(thread_frame)
                if stack:
                    current_node = self.profile
                    for frame in reversed(stack):
                        current_node = current_node.find_or_add_child(str(frame))
                        current_node.set_type(Breakdown.TYPE_CALLSITE)
                    current_node.increment(sample_time, 1)

                thread_id, thread_frame, stack = None, None, None

            items = None
            current_frames = None 
開發者ID:stackimpact,項目名稱:stackimpact-python,代碼行數:24,代碼來源:block_profiler.py


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