本文整理匯總了Python中threading.settrace方法的典型用法代碼示例。如果您正苦於以下問題:Python threading.settrace方法的具體用法?Python threading.settrace怎麽用?Python threading.settrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類threading
的用法示例。
在下文中一共展示了threading.settrace方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_finalize_with_trace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def test_finalize_with_trace(self):
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
assert_python_ok("-c", """if 1:
import sys, threading
# A deadlock-killer, to prevent the
# testsuite to hang forever
def killer():
import os, time
time.sleep(2)
print('program blocked; aborting')
os._exit(2)
t = threading.Thread(target=killer)
t.daemon = True
t.start()
# This is the trace function
def func(frame, event, arg):
threading.current_thread()
return func
sys.settrace(func)
""")
示例2: __call__
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def __call__(self, frame, kind, arg):
"""
The settrace function.
.. note::
This always returns self (drills down) - as opposed to only drilling down when ``predicate(event)`` is True
because it might match further inside.
"""
if self._handler is not None:
if kind == 'return' and self.depth > 0:
self.depth -= 1
try:
self._handler(Event(frame, kind, arg, self))
except Exception as exc:
traceback.print_exc(file=hunter._default_stream)
hunter._default_stream.write('Disabling tracer because handler {} failed ({!r}).\n\n'.format(
self._handler, exc))
self.stop()
return
if kind == 'call':
self.depth += 1
self.calls += 1
return self
示例3: trace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def trace(self, predicate):
"""
Starts tracing with the given callable.
Args:
predicate (callable that accepts a single :obj:`~hunter.event.Event` argument):
Return:
self
"""
self._handler = predicate
if self.threading_support is None or self.threading_support:
self._threading_previous = getattr(threading, '_trace_hook', None)
threading.settrace(self)
self._previous = sys.gettrace()
sys.settrace(self)
return self
示例4: runfunc
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def runfunc(*args, **kw):
if len(args) >= 2:
self, func, *args = args
elif not args:
raise TypeError("descriptor 'runfunc' of 'Trace' object "
"needs an argument")
elif 'func' in kw:
func = kw.pop('func')
self, *args = args
else:
raise TypeError('runfunc expected at least 1 positional argument, '
'got %d' % (len(args)-1))
result = None
if not self.donothing:
sys.settrace(self.globaltrace)
try:
result = func(*args, **kw)
finally:
if not self.donothing:
sys.settrace(None)
return result
示例5: stoptrace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def stoptrace():
global connected
if connected:
pydevd_tracing.restore_sys_set_trace_func()
sys.settrace(None)
try:
#not available in jython!
threading.settrace(None) # for all future threads
except:
pass
from _pydev_bundle.pydev_monkey import undo_patch_thread_modules
undo_patch_thread_modules()
debugger = get_global_debugger()
if debugger:
debugger.set_trace_for_frame_and_parents(
get_frame(), also_add_to_passed_frame=True, overwrite_prev_trace=True, dispatch_func=lambda *args:None)
debugger.exiting()
kill_all_pydev_threads()
connected = False
示例6: _unsettrace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def _unsettrace():
sys.settrace(None)
示例7: _settrace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def _settrace(func):
threading.settrace(func)
sys.settrace(func)
示例8: run
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def run(self, cmd):
import __main__
dict = __main__.__dict__
if not self.donothing:
threading.settrace(self.globaltrace)
sys.settrace(self.globaltrace)
try:
exec cmd in dict, dict
finally:
if not self.donothing:
sys.settrace(None)
threading.settrace(None)
示例9: runfunc
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def runfunc(self, func, *args, **kw):
result = None
if not self.donothing:
sys.settrace(self.globaltrace)
try:
result = func(*args, **kw)
finally:
if not self.donothing:
sys.settrace(None)
return result
示例10: test_finalize_with_trace
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def test_finalize_with_trace(self):
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
p = subprocess.Popen([sys.executable, "-c", """if 1:
import sys, threading
# A deadlock-killer, to prevent the
# testsuite to hang forever
def killer():
import os, time
time.sleep(2)
print 'program blocked; aborting'
os._exit(2)
t = threading.Thread(target=killer)
t.daemon = True
t.start()
# This is the trace function
def func(frame, event, arg):
threading.current_thread()
return func
sys.settrace(func)
"""],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close)
stdout, stderr = p.communicate()
rc = p.returncode
self.assertFalse(rc == 2, "interpreted was blocked")
self.assertTrue(rc == 0,
"Unexpected error: " + repr(stderr))
示例11: enable
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def enable(self):
"""enable logging on all threads."""
assert(self.fh is not None)
sys.settrace(self.__callback)
threading.settrace(self.__callback)
示例12: disable
# 需要導入模塊: import threading [as 別名]
# 或者: from threading import settrace [as 別名]
def disable(self):
"""disable logging on all threads."""
sys.settrace(None)
threading.settrace(None)