sys.settrace

Here are the examples of the python api sys.settrace taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

200 Examples 7

Example 1

Project: WAPT
Source File: bdb.py
View license
    def set_continue(self):
        # Don't stop except at breakpoints or when finished
        self._set_stopinfo(self.botframe, None, -1)
        if not self.breaks:
            # no breakpoints; run without debugger overhead
            sys.settrace(None)
            frame = sys._getframe().f_back
            while frame and frame is not self.botframe:
                del frame.f_trace
                frame = frame.f_back

Example 2

Project: python-web-pdb
Source File: __init__.py
View license
    def remove_trace(self, frame=None):
        """
        Detach the debugger from the execution stack

        :param frame: the lowest frame to detach the debugger from.
        """
        sys.settrace(None)
        if frame is None:
            frame = self.curframe
        while frame and frame is not self.botframe:
            del frame.f_trace
            frame = frame.f_back

Example 3

Project: Limnoria
Source File: plugin.py
View license
    def unsettrace(self, irc, msg, args):
        """takes no arguments

        Stops tracing function calls on stdout.
        """
        sys.settrace(None)
        irc.replySuccess()

Example 4

Project: imagrium
Source File: bdb.py
View license
    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)

Example 5

Project: conary
Source File: __init__.py
View license
    def do_debug(self, arg):
        sys.settrace(None)
        globals = self.curframe.f_globals
        locals = self.curframe.f_locals
        p = Epdb()
        p.prompt = "(%s) " % self.prompt.strip()
        print "ENTERING RECURSIVE DEBUGGER"
        sys.call_tracing(p.run, (arg, globals, locals))
        print "LEAVING RECURSIVE DEBUGGER"
        sys.settrace(self.trace_dispatch)
        self.lastcmd = p.lastcmd

Example 6

Project: PipelineConstructionSet
Source File: coverage.py
View license
    def stop(self):
        self.nesting -= 1
        if self.nesting == 0:                               #pragma: no cover
            sys.settrace(None)
            if hasattr(threading, 'settrace'):
                threading.settrace(None)

Example 7

Project: TrustRouter
Source File: test_sys_settrace.py
View license
    def run_test(self, func):
        tracer = JumpTracer(func)
        sys.settrace(tracer.trace)
        output = []
        func(output)
        sys.settrace(None)
        self.compare_jump_output(func.output, output)

Example 8

Project: linkchecker
Source File: trace.py
View license
def trace_on (full=False):
    """Start tracing of the current thread (and the current thread only)."""
    if full:
        sys.settrace(_trace_full)
    else:
        sys.settrace(_trace)

Example 9

Project: DarkPython
Source File: debugger.py
View license
	def run(self):
		import __main__
		globals = __main__.__dict__
		locals = globals
		self.reset()
		sys.settrace(self.trace_dispatch)
		#if not isinstance(self.code, types.CodeType):
		#	self.code = self.code+'\n'
		try:
			exec self.code in globals, locals
		except BdbQuit:
			pass
		finally:
			self.quitting = 1
			sys.settrace(None)

Example 10

Project: termite-data-server
Source File: qdb.py
View license
def quit():
    "Remove trace and quit"
    global qdb, listener, conn
    if qdb:
        sys.settrace(None)
        qdb = None
    if conn:
        conn.close()
        conn = None
    if listener:
        listener.close()
        listener = None

Example 11

Project: rad2py
Source File: qdb.py
View license
def quit():
    "Remove trace and quit"
    global qdb, listener, conn
    if qdb:
        sys.settrace(None)
        qdb = None
    if conn:
        conn.close()
        conn = None
    if listener:
        listener.close() 
        listener = None

Example 12

Project: nodeset.core
Source File: __init__.py
View license
    def loadTestsFromNames(self, test_suite, wtf):
        config = Options()
        config.parseOptions(test_suite)
                                
        trialRunner = _makeRunner(config)
        suite = _getSuite(config)
        if config['until-failure']:
            test_result = trialRunner.runUntilFailure(suite)
        else:
            test_result = trialRunner.run(suite)
        if config.tracer:
            sys.settrace(None)
            results = config.tracer.results()
            results.write_results(show_missing=1, summary=False,
                                  coverdir=config.coverdir)
            
        sys.exit(not test_result.wasSuccessful())

Example 13

Project: peek
Source File: collector.py
View license
    def _installation_trace(self, origin):
        """
        Called on new threads, installs the real tracer.
        """
        def _wrapped(frame_unused, event_unused, arg_unused):
            # Remove ourselves as the trace function
            sys.settrace(None)

            # Install the real tracer.
            fn = self._start_tracer(origin)

            # Invoke the real trace function with the current event, to be sure
            # not to lose an event.
            if fn:
                fn = fn(frame_unused, event_unused, arg_unused)

            # Return the new trace function to continue tracing in this scope.
            return fn
        return _wrapped

Example 14

Project: flumotion
Source File: debug.py
View license
def trace_stop():
    global _tracing, _indent
    assert _tracing > 0
    _tracing -= 1
    if not _tracing:
        sys.settrace(None)
        _indent = ''

Example 15

Project: canape
Source File: bdb.py
View license
    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)

Example 16

Project: EmPyre
Source File: agent.py
View license
    def __run(self):
        """Hacked run function, which installs the
    trace."""
        sys.settrace(self.globaltrace)
        self.__run_backup()
        self.run = self.__run_backup

Example 17

Project: brython
Source File: test_sys_settrace.py
View license
    def test_set_and_retrieve_func(self):
        def fn(*args):
            pass

        sys.settrace(fn)
        try:
            assert sys.gettrace() is fn
        finally:
            sys.settrace(None)

Example 18

Project: pprofile
Source File: pprofile.py
View license
    def disable(self, threads=True):
        """
        Disable profiling.
        """
        if self.enabled_start:
            sys.settrace(None)
            self._disable()
        else:
            warn('Duplicate "disable" call')

Example 19

Project: chipsec
Source File: test_sys_settrace.py
View license
    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
            jump = (2, 0)
        tracer = JumpTracer(fake_function)
        sys.settrace(tracer.trace)
        namespace = {"output": []}
        exec code in namespace
        sys.settrace(None)
        self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"])

Example 20

Project: babble
Source File: test_trace.py
View license
    def run_and_compare(self, func, events):
        tracer = Tracer()
        sys.settrace(tracer.trace)
        func()
        sys.settrace(None)
        self.compare_events(func.func_code.co_firstlineno,
                            tracer.events, events)

Example 21

Project: fwlite
Source File: bdb.py
View license
    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)

Example 22

Project: autotest
Source File: coverage.py
View license
    def start(self, parallel_mode=False):
        self.get_ready()
        if self.nesting == 0:  # pragma: no cover
            sys.settrace(self.t)
            if hasattr(threading, 'settrace'):
                threading.settrace(self.t)
        self.nesting += 1

Example 23

Project: fwlite
Source File: bdb.py
View license
    def runcall(self, func, *args, **kwds):
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None)
        return res

Example 24

Project: PokemonGo-Bot-Desktop
Source File: pdb.py
View license
    def do_debug(self, arg):
        sys.settrace(None)
        globals = self.curframe.f_globals
        locals = self.curframe_locals
        p = Pdb(self.completekey, self.stdin, self.stdout)
        p.prompt = "(%s) " % self.prompt.strip()
        print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
        sys.call_tracing(p.run, (arg, globals, locals))
        print >>self.stdout, "LEAVING RECURSIVE DEBUGGER"
        sys.settrace(self.trace_dispatch)
        self.lastcmd = p.lastcmd

Example 25

Project: pprofile
Source File: pprofile.py
View license
    def enable(self):
        """
        Enable profiling.
        """
        if self.enabled_start:
            warn('Duplicate "enable" call')
        else:
            self._enable()
            sys.settrace(self._global_trace)

Example 26

Project: peek
Source File: tracer.py
View license
    def start(self, origin):
        """
        Start this Tracer.

        Return a Python function suitable for use with sys.settrace().
        """
        self.start_time = time.time()
        self.pause_until = None
        self.data.update(self._get_struct(origin, 'origin'))
        self.data_stack.append(self.data)
        sys.settrace(self._trace)
        return self._trace

Example 27

Project: PokemonGo-Bot-Desktop
Source File: trace.py
View license
    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

Example 28

Project: databus
Source File: trace.py
View license
    def run(self, cmd):
        import __main__
        dict = __main__.__dict__
        if not self.donothing:
            sys.settrace(self.globaltrace)
            threading.settrace(self.globaltrace)
        try:
            exec cmd in dict, dict
        finally:
            if not self.donothing:
                sys.settrace(None)
                threading.settrace(None)

Example 29

Project: canape
Source File: bdb.py
View license
    def runcall(self, func, *args, **kwds):
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None)
        return res

Example 30

Project: databus
Source File: trace.py
View license
    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

Example 31

Project: imagrium
Source File: bdb.py
View license
    def runcall(self, func, *args, **kwds):
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None)
        return res

Example 32

Project: RouteFlow
Source File: recoco_spy.py
View license
def launch ():
  def f ():
    import sys
    sys.settrace(_tf)
  core.callLater(f)

  import threading
  _trace_thread = threading.Thread(target=_trace_thread_proc)
  _trace_thread.daemon = True
  _trace_thread.start()

Example 33

Project: PipelineConstructionSet
Source File: coverage.py
View license
    def start(self, parallel_mode=False):
        self.get_ready()
        if self.nesting == 0:                               #pragma: no cover
            sys.settrace(self.t)
            if hasattr(threading, 'settrace'):
                threading.settrace(self.t)
        self.nesting += 1

Example 34

View license
    def test_preserving_previous_function(self):

        sys.settrace(self.bar)
        with self.monitor:
            self.foo()
        self.assertIs(sys.gettrace(), self.bar)

Example 35

Project: WAPT
Source File: bdb.py
View license
    def runcall(self, func, *args, **kwds):
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None)
        return res

Example 36

Project: chipsec
Source File: pdb.py
View license
    def do_debug(self, arg):
        sys.settrace(None)
        globals = self.curframe.f_globals
        locals = self.curframe_locals
        p = Pdb(self.completekey, self.stdin, self.stdout)
        p.prompt = "(%s) " % self.prompt.strip()
        print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
        sys.call_tracing(p.run, (arg, globals, locals))
        print >>self.stdout, "LEAVING RECURSIVE DEBUGGER"
        sys.settrace(self.trace_dispatch)
        self.lastcmd = p.lastcmd

Example 37

Project: PythonScript
Source File: bdb.py
View license
    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)

Example 38

Project: chipsec
Source File: test_sys_settrace.py
View license
    def run_test(self, func):
        tracer = JumpTracer(func)
        sys.settrace(tracer.trace)
        output = []
        func(output)
        sys.settrace(None)
        self.compare_jump_output(func.output, output)

Example 39

Project: TrustRouter
Source File: test_sys_settrace.py
View license
    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:
            __code__ = code
            jump = (2, 0)
        tracer = JumpTracer(fake_function)
        sys.settrace(tracer.trace)
        namespace = {"output": []}
        exec(code, namespace)
        sys.settrace(None)
        self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"])

Example 40

Project: obiwan
Source File: __init__.py
View license
def install_obiwan_runtime_check():
    global _enabled
    _enabled = True
    sys.settrace(_runtime_checker)
    def disable():
        global _enabled
        _enabled = False
    atexit.register(disable)

Example 41

Project: bh2014
Source File: bdb.py
View license
    def runcall(self, func, *args, **kwds):
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = 1
            sys.settrace(None)
        return res

Example 42

Project: pikos
Source File: trace_function_manager.py
View license
    def recover(self):
        """ Unset the current function in the sys.settrace.

        If available the previous method is recovered in settrace. A
        RuntimeError is raised if the `previous` attribute does not exist.

        """
        if hasattr(self, 'previous'):
            sys.settrace(self.previous)
            if has_threading:
                threading.settrace(self.previous)
            del self.previous
        else:
            raise RuntimeError('A profile function has not been set')

Example 43

Project: oleviewdotnet
Source File: pdb.py
View license
    def do_debug(self, arg):
        sys.settrace(None)
        globals = self.curframe.f_globals
        locals = self.curframe_locals
        p = Pdb(self.completekey, self.stdin, self.stdout)
        p.prompt = "(%s) " % self.prompt.strip()
        print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
        sys.call_tracing(p.run, (arg, globals, locals))
        print >>self.stdout, "LEAVING RECURSIVE DEBUGGER"
        sys.settrace(self.trace_dispatch)
        self.lastcmd = p.lastcmd

Example 44

Project: termite-visualizations
Source File: qdb.py
View license
def quit():
    "Remove trace and quit"
    global qdb, listener, conn
    if qdb:
        sys.settrace(None)
        qdb = None
    if conn:
        conn.close()
        conn = None
    if listener:
        listener.close()
        listener = None

Example 45

Project: datafari
Source File: bdb.py
View license
    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)

Example 46

Project: ocf
Source File: tracer.py
View license
  def disable (self):
    sys.settrace(None)
    sys.setprofile(None)

    path = self.cur_fpath

    self.cur_fobj.flush()
    self.cur_fobj.close()
    self.cur_fobj = None
    self.cur_fpath = None

    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__

    return path

Example 47

Project: ocf
Source File: tracer.py
View license
  def enable (self):
    sys.settrace(None)
    sys.setprofile(None)

    self.cur_fpath = "%s/trace.%f.log" % (LOGDIR, time.time())
    self.cur_fobj = open(self.cur_fpath, "w")

    sys.stdout = self.cur_fobj
    sys.stderr = self.cur_fobj

    sys.settrace(tracer)
    sys.setprofile(tracer_c)

Example 48

Project: PyDev.Debugger
Source File: pydevd_tracing.py
View license
def SetTrace(tracing_func):
    if TracingFunctionHolder._original_tracing is None:
        #This may happen before replace_sys_set_trace_func is called.
        sys.settrace(tracing_func)
        return

    TracingFunctionHolder._lock.acquire()
    try:
        TracingFunctionHolder._warn = False
        _internal_set_trace(tracing_func)
        TracingFunctionHolder._warn = True
    finally:
        TracingFunctionHolder._lock.release()

Example 49

Project: babble
Source File: test_trace.py
View license
    def run_test2(self, func):
        tracer = Tracer()
        func(tracer.trace)
        sys.settrace(None)
        self.compare_events(func.func_code.co_firstlineno,
                            tracer.events, func.events)

Example 50

Project: autotest
Source File: coverage.py
View license
    def stop(self):
        self.nesting -= 1
        if self.nesting == 0:  # pragma: no cover
            sys.settrace(None)
            if hasattr(threading, 'settrace'):
                threading.settrace(None)