本文整理汇总了Python中sys.setprofile方法的典型用法代码示例。如果您正苦于以下问题:Python sys.setprofile方法的具体用法?Python sys.setprofile怎么用?Python sys.setprofile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.setprofile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_trace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def set_trace(self, frame=None):
"""Starts debugging from 'frame'"""
if frame is None:
frame = sys._getframe().f_back # Skip set_trace method
if sys.version_info[0] == 2:
stopOnHandleLine = self._dbgClient.handleLine.func_code
else:
stopOnHandleLine = self._dbgClient.handleLine.__code__
frame.f_trace = self.trace_dispatch
while frame.f_back is not None:
# stop at erics debugger frame or a threading bootstrap
if frame.f_back.f_code == stopOnHandleLine:
frame.f_trace = self.trace_dispatch
break
frame = frame.f_back
self.stop_everywhere = True
sys.settrace(self.trace_dispatch)
sys.setprofile(self._dbgClient.callTraceEnabled)
示例2: deferral
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def deferral():
"""Defers a function call when it is being required like Go.
::
with deferral() as defer:
sys.setprofile(f)
defer(sys.setprofile, None)
# do something.
"""
deferred = []
defer = lambda f, *a, **k: deferred.append((f, a, k))
try:
yield defer
finally:
while deferred:
f, a, k = deferred.pop()
f(*a, **k)
示例3: run
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def run(self):
if sys.getprofile() is not None:
# NOTE: There's no threading.getprofile().
# The profiling function will be stored at threading._profile_hook
# but it's not documented.
raise RuntimeError('Another profiler already registered')
with deferral() as defer:
self._times_entered.clear()
self.overhead = 0.0
sys.setprofile(self._profile)
defer(sys.setprofile, None)
threading.setprofile(self._profile)
defer(threading.setprofile, None)
self.timer.start(self)
defer(self.timer.stop)
yield
示例4: test_tracing_sampler_does_not_sample_too_often
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def test_tracing_sampler_does_not_sample_too_often():
pytest.importorskip('yappi')
# pytest-cov cannot detect a callback function registered by
# :func:`sys.setprofile`.
class fake_profiler(object):
samples = []
@classmethod
def sample(cls, frame):
cls.samples.append(frame)
@classmethod
def count_and_clear_samples(cls):
count = len(cls.samples)
del cls.samples[:]
return count
sampler = TracingSampler(0.1)
sampler._profile(fake_profiler, None, None, None)
assert fake_profiler.count_and_clear_samples() == 1
sampler._profile(fake_profiler, None, None, None)
assert fake_profiler.count_and_clear_samples() == 0
spin(0.5)
sampler._profile(fake_profiler, None, None, None)
assert fake_profiler.count_and_clear_samples() == 1
示例5: start
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def start(self):
self.last_profile_time = timer()
if self.use_signal:
try:
signal.signal(signal.SIGALRM, self._signal)
# the following tells the system to restart interrupted system calls if they are
# interrupted before any data has been transferred. This avoids many of the problems
# related to signals interrupting system calls, see issue #16
signal.siginterrupt(signal.SIGALRM, False)
except ValueError:
raise NotMainThreadError()
signal.setitimer(signal.ITIMER_REAL, self.interval, 0.0)
else:
sys.setprofile(self._profile)
示例6: test_getdefaultencoding
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def test_getdefaultencoding(self):
if test.test_support.have_unicode:
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
# can't check more than the type, as the user might have changed it
self.assertIsInstance(sys.getdefaultencoding(), str)
# testing sys.settrace() is done in test_sys_settrace.py
# testing sys.setprofile() is done in test_sys_setprofile.py
示例7: setprofile
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def setprofile(func):
"""Set a profile function for all threads started from the threading module.
The func will be passed to sys.setprofile() for each thread, before its
run() method is called.
"""
global _profile_hook
_profile_hook = func
示例8: setCallTrace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def setCallTrace(self, enabled):
"""Sets up the call trace"""
if enabled:
sys.setprofile(self.profile)
self.callTraceEnabled = self.profile
else:
sys.setprofile(None)
self.callTraceEnabled = None
示例9: fork
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def fork(self):
"""fork routine deciding which branch to follow"""
# It does not make sense to follow something which was run via the
# subprocess module. The subprocess module uses fork() internally,
# so let's analyze it and do auto follow parent even if it was not
# required explicitly.
isPopen = False
stackFrames = traceback.extract_stack()
for stackFrame in stackFrames:
if stackFrame[2] == '_execute_child':
if stackFrame[0].endswith(os.path.sep + 'subprocess.py'):
isPopen = True
if not self.forkAuto and not isPopen:
sendJSONCommand(self.socket, METHOD_FORK_TO,
self.procuuid, None)
self.eventLoop(True)
pid = DEBUG_CLIENT_ORIG_FORK()
if isPopen:
# Switch to following parent
oldFollow = self.forkChild
self.forkChild = False
if pid == 0:
# child
if not self.forkChild:
sys.settrace(None)
sys.setprofile(None)
self.sessionClose(False)
else:
# parent
if self.forkChild:
sys.settrace(None)
sys.setprofile(None)
self.sessionClose(False)
if isPopen:
# Switch to what it was before
self.forkChild = oldFollow
return pid
示例10: bootstrap
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def bootstrap(self, target, args, kwargs):
"""Bootstraps a thread"""
try:
# Because in the initial run method the "base debug" function is
# set up, it's also valid for the threads afterwards.
sys.settrace(self.trace_dispatch)
target(*args, **kwargs)
except Exception:
excinfo = sys.exc_info()
self.user_exception(excinfo, True)
finally:
sys.settrace(None)
sys.setprofile(None)
示例11: set_continue
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def set_continue(self, special):
"""Stops only on next breakpoint"""
# Here we only set a new stop frame if it is a normal continue.
if not special:
self._set_stopinfo(None, None)
# Disable tracing if not started in debug mode
if not self._dbgClient.debugging:
sys.settrace(None)
sys.setprofile(None)
示例12: runctx
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def runctx(self, cmd, globals, locals):
self.set_cmd(cmd)
sys.setprofile(self.dispatcher)
try:
exec cmd in globals, locals
finally:
sys.setprofile(None)
return self
# This method is more useful to profile a single function call.
示例13: setprofile
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def setprofile(func):
global _profile_hook
_profile_hook = func
示例14: setUp
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def setUp(self):
sys.setprofile(None)
示例15: tearDown
# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def tearDown(self):
sys.setprofile(None)