本文整理汇总了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))
示例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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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))
示例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
示例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))
示例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
示例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)
示例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()
示例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
示例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