当前位置: 首页>>代码示例>>Python>>正文


Python sys.settrace方法代码示例

本文整理汇总了Python中sys.settrace方法的典型用法代码示例。如果您正苦于以下问题:Python sys.settrace方法的具体用法?Python sys.settrace怎么用?Python sys.settrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.settrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_trace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [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) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:24,代码来源:base_cdm_dbg.py

示例2: updateSysTrace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def updateSysTrace(self):
        ## Install or uninstall  sys.settrace handler 
        
        if not self.ui.catchNextExceptionBtn.isChecked() and not self.ui.catchAllExceptionsBtn.isChecked():
            if sys.gettrace() == self.systrace:
                sys.settrace(None)
            return
        
        if self.ui.onlyUncaughtCheck.isChecked():
            if sys.gettrace() == self.systrace:
                sys.settrace(None)
        else:
            if sys.gettrace() is not None and sys.gettrace() != self.systrace:
                self.ui.onlyUncaughtCheck.setChecked(False)
                raise Exception("sys.settrace is in use; cannot monitor for caught exceptions.")
            else:
                sys.settrace(self.systrace) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:19,代码来源:Console.py

示例3: restore_settrace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def restore_settrace(monkeypatch):
    """(Re)store sys.gettrace after test run.

    This is required to re-enable coverage tracking.
    """
    assert sys.gettrace() is _orig_trace

    orig_settrace = sys.settrace

    # Wrap sys.settrace to restore original tracing function (coverage)
    # with `sys.settrace(None)`.
    def settrace(func):
        if func is None:
            orig_settrace(_orig_trace)
        else:
            orig_settrace(func)
    monkeypatch.setattr("sys.settrace", settrace)

    yield

    newtrace = sys.gettrace()
    if newtrace is not _orig_trace:
        sys.settrace(_orig_trace)
        assert newtrace is None 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:26,代码来源:conftest.py

示例4: run

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def run(self, cmd, globals=None, locals=None):
        if globals is None:
            import __main__
            globals = __main__.__dict__
        if locals is None:
            locals = globals
        self.reset()
        sys.settrace(self.trace_dispatch)
        if not isinstance(cmd, types.CodeType):
            cmd = cmd+'\n'
        try:
            exec cmd in globals, locals
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None) 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:bdb.py

示例5: dispatch_call

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def dispatch_call(self, frame, arg):
        traceenter("dispatch_call",_dumpf(frame))
        frame.f_locals['__axstack_address__'] = axdebug.GetStackAddress()
        if frame is self.botframe:
            trace("dispatch_call is self.botframe - returning tracer")
            return self.trace_dispatch
        # Not our bottom frame.  If we have a document for it,
        # then trace it, otherwise run at full speed.
        if self.codeContainerProvider.FromFileName(frame.f_code.co_filename) is None:
            trace("dispatch_call has no document for", _dumpf(frame), "- skipping trace!")
##                      sys.settrace(None)
            return None
        return self.trace_dispatch

#               rc =  bdb.Bdb.dispatch_call(self, frame, arg)
#               trace("dispatch_call", _dumpf(frame),"returned",rc)
#               return rc 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:adb.py

示例6: post_mortem

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def post_mortem(t=None):
	if t is None:
		t = sys.exc_info()[2] # Will be valid if we are called from an except handler.
	if t is None:
		try:
			t = sys.last_traceback
		except AttributeError:
			print "No traceback can be found from which to perform post-mortem debugging!"
			print "No debugging can continue"
			return
	p = _GetCurrentDebugger()
	if p.frameShutdown: return # App closing
	# No idea why I need to settrace to None - it should have been reset by now?
	sys.settrace(None)
	p.reset()
	while t.tb_next != None: t = t.tb_next
	p.bAtPostMortem = 1
	p.prep_run(None)
	try:
		p.interaction(t.tb_frame, t)
	finally:
		t = None
		p.bAtPostMortem = 0
		p.done_run() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:__init__.py

示例7: set_trace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def set_trace(self):
		# Start debugging from _2_ levels up!
		try:
			1 + ''
		except:
			frame = sys.exc_info()[2].tb_frame.f_back.f_back
		self.reset()
		self.userbotframe = None
		while frame:
			# scriptutils.py creates a local variable with name
			# '_debugger_stop_frame_', and we dont go past it
			# (everything above this is Pythonwin framework code)
			if "_debugger_stop_frame_" in frame.f_locals:
				self.userbotframe = frame
				break

			frame.f_trace = self.trace_dispatch
			self.botframe = frame
			frame = frame.f_back
		self.set_step()
		sys.settrace(self.trace_dispatch) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:debugger.py

示例8: testLocalsClass_WithTrace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def testLocalsClass_WithTrace(self):
        # Issue23728: after the trace function returns, the locals()
        # dictionary is used to update all variables, this used to
        # include free variables. But in class statements, free
        # variables are not inserted...
        import sys
        sys.settrace(lambda a,b,c:None)
        try:
            x = 12

            class C:
                def f(self):
                    return x

            self.assertEqual(x, 12) # Used to raise UnboundLocalError
        finally:
            sys.settrace(None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_scope.py

示例9: testInteractionWithTraceFunc

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def testInteractionWithTraceFunc(self):

        import sys
        def tracer(a,b,c):
            return tracer

        def adaptgetter(name, klass, getter):
            kind, des = getter
            if kind == 1:       # AV happens when stepping from this line to next
                if des == "":
                    des = "_%s__%s" % (klass.__name__, name)
                return lambda obj: getattr(obj, des)

        class TestClass:
            pass

        sys.settrace(tracer)
        adaptgetter("foo", TestClass, (1, ""))
        sys.settrace(None)

        self.assertRaises(TypeError, sys.settrace) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_scope.py

示例10: run_test_for_event

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def run_test_for_event(self, event):
        """Tests that an exception raised in response to the given event is
        handled OK."""
        self.raiseOnEvent = event
        try:
            for i in xrange(sys.getrecursionlimit() + 1):
                sys.settrace(self.trace)
                try:
                    self.f()
                except ValueError:
                    pass
                else:
                    self.fail("exception not raised!")
        except RuntimeError:
            self.fail("recursion counter not reset")

    # Test the handling of exceptions raised by each kind of trace event. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_sys_settrace.py

示例11: test_trash_stack

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def test_trash_stack(self):
        def f():
            for i in range(5):
                print i  # line tracing will raise an exception at this line

        def g(frame, why, extra):
            if (why == 'line' and
                frame.f_lineno == f.func_code.co_firstlineno + 2):
                raise RuntimeError, "i am crashing"
            return g

        sys.settrace(g)
        try:
            f()
        except RuntimeError:
            # the test is really that this doesn't segfault:
            import gc
            gc.collect()
        else:
            self.fail("exception not propagated")


# 'Jump' tests: assigning to frame.f_lineno within a trace function
# moves the execution position - it's how debuggers implement a Jump
# command (aka. "Set next statement"). 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_sys_settrace.py

示例12: test_jump_to_firstlineno

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def test_jump_to_firstlineno(self):
        # This tests that PDB can jump back to the first line in a
        # file.  See issue #1689458.  It can only be triggered in a
        # function call if the function is defined on a single line.
        code = compile("""
# Comments don't count.
output.append(2)  # firstlineno is here.
output.append(3)
output.append(4)
""", "<fake module>", "exec")
        class fake_function:
            func_code = code
        tracer = JumpTracer(fake_function, 2, 0)
        sys.settrace(tracer.trace)
        namespace = {"output": []}
        exec code in namespace
        sys.settrace(None)
        self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_sys_settrace.py

示例13: no_tracing

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def no_tracing(func):
    """Decorator to temporarily turn off tracing for the duration of a test."""
    if not hasattr(sys, 'gettrace'):
        return func
    else:
        def wrapper(*args, **kwargs):
            original_trace = sys.gettrace()
            try:
                sys.settrace(None)
                return func(*args, **kwargs)
            finally:
                sys.settrace(original_trace)
        wrapper.__name__ = func.__name__
        return wrapper


# Return True if opcode code appears in the pickle, else False. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:pickletester.py

示例14: runeval

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def runeval(self, expr, globals=None, locals=None):
        if globals is None:
            import __main__
            globals = __main__.__dict__
        if locals is None:
            locals = globals
        self.reset()
        sys.settrace(self.trace_dispatch)
        if not isinstance(expr, types.CodeType):
            expr = expr+'\n'
        try:
            return eval(expr, globals, locals)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:bdb.py

示例15: test_call_tracing

# 需要导入模块: import sys [as 别名]
# 或者: from sys import settrace [as 别名]
def test_call_tracing(self):
        def f(i):
            return i * 2
        def g():
            pass

        # outside of a traceback
        self.assertEqual(10, sys.call_tracing(f, (5, )))

        # inside of a traceback
        log = []
        def thandler(frm, evt, pl):
            if evt == 'call':
                log.append(frm.f_code.co_name)
                if log[-1] == 'g':
                    sys.call_tracing(f, (5, ))
            return thandler

        sys.settrace(thandler)
        g()
        sys.settrace(None)

        self.assertEqual(log, ['g', 'f']) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_sys.py


注:本文中的sys.settrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。