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.

181 Examples 7

3 Source : bdb.py
with Apache License 2.0
from 1020528175

    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

    def set_quit(self):

3 Source : bdb.py
with Apache License 2.0
from 1020528175

    def set_quit(self):
        self.stopframe = self.botframe
        self.returnframe = None
        self.quitting = 1
        sys.settrace(None)

    # Derived classes and clients can call the following methods
    # to manipulate breakpoints.  These methods return an
    # error message is something went wrong, None if all is well.
    # Set_break prints out the breakpoint line and file:lineno.
    # Call self.get_*break*() to see the breakpoints or better
    # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().

    def set_break(self, filename, lineno, temporary=0, cond = None,

3 Source : bdb.py
with Apache License 2.0
from 1020528175

    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)

    def runeval(self, expr, globals=None, locals=None):

3 Source : bdb.py
with Apache License 2.0
from 1020528175

    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)

    def runctx(self, cmd, globals, locals):

3 Source : bdb.py
with Apache License 2.0
from 1020528175

    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


def set_trace():

3 Source : pdb.py
with Apache License 2.0
from 1020528175

    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

    def do_quit(self, arg):

3 Source : trace.py
with Apache License 2.0
from 1020528175

    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

    def file_module_function_of(self, frame):

3 Source : test_scope.py
with GNU General Public License v3.0
from adityaprakash-bobby

    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)

    def testBoundAndFree(self):

3 Source : test_sys_settrace.py
with GNU General Public License v3.0
from adityaprakash-bobby

    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)

    def run_test(self, func):

3 Source : test_sys_settrace.py
with GNU General Public License v3.0
from adityaprakash-bobby

    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)

    def test_set_and_retrieve_none(self):

3 Source : test_sys_settrace.py
with GNU General Public License v3.0
from adityaprakash-bobby

    def test_set_and_retrieve_func(self):
        def fn(*args):
            pass

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

    def test_01_basic(self):

3 Source : test_sys_settrace.py
with GNU General Public License v3.0
from adityaprakash-bobby

    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)

    def test_01_jump_simple_forwards(self):

3 Source : tracer2.py
with MIT License
from alexmojaki

    def __exit__(self, exc_type, exc_value, exc_traceback, context=0):
        if not self.config.enabled:
            return

        stack = thread_global.original_trace_functions
        sys.settrace(stack.pop())
        calling_frame = sys._getframe(context + 1)
        self.trace(calling_frame, 'exit', None)
        self.target_frames.discard(calling_frame)
        self.frame_infos.pop(calling_frame, None)

    def _is_internal_frame(self, frame):

3 Source : tracer.py
with MIT License
from alexmojaki

    def __exit__(self, exc_type, exc_value, exc_traceback, context=0):
        if not self.config.enabled:
            return

        previous_trace = thread_global.original_trace_functions.pop()
        sys.settrace(previous_trace)
        calling_frame = sys._getframe(context + 1)
        if not (PY34 and previous_trace is None):
            calling_frame.f_trace = previous_trace
        self.trace(calling_frame, 'exit', None)
        self.target_frames.discard(calling_frame)
        self.frame_infos.pop(calling_frame, None)

    def _is_internal_frame(self, frame):

3 Source : debug.py
with MIT License
from Amirh24

def spew(trace_names=None, show_values=False):
    """Install a trace hook which writes incredibly detailed logs
    about what code is being executed to stdout.
    """
    sys.settrace(Spew(trace_names, show_values))


def unspew():

3 Source : memory.py
with MIT License
from andyljones

    def register_callback(self):
        """Register the trace_callback only on demand"""
        if self._code_infos:
            sys.settrace(self._trace_callback)

    def _reset_cuda_stats(self):

3 Source : app.py
with MIT License
from autofelix

    def opt_spew(self):
        """
        Print an insanely verbose log of everything that happens.
        Useful when debugging freezes or locks in complex code.
        """
        sys.settrace(util.spewer)
        try:
            import threading
        except ImportError:
            return
        threading.settrace(util.spewer)


    def parseOptions(self, options=None):

3 Source : trial.py
with MIT License
from autofelix

    def opt_coverage(self):
        """
        Generate coverage information in the coverage file in the
        directory specified by the temp-directory option.
        """
        import trace
        self.tracer = trace.Trace(count=1, trace=0)
        sys.settrace(self.tracer.globaltrace)
        self['coverage'] = True


    def opt_testmodule(self, filename):

3 Source : trial.py
with MIT License
from autofelix

    def opt_spew(self):
        """
        Print an insanely verbose log of everything that happens.  Useful
        when debugging freezes or locks in complex code.
        """
        from twisted.python.util import spewer
        sys.settrace(spewer)


    def opt_help_orders(self):

3 Source : test_script.py
with MIT License
from autofelix

    def setUp(self):
        """
        Arrange for the current trace hook to be restored when the
        test is complete.
        """
        self.addCleanup(sys.settrace, sys.gettrace())


    def test_tracerInstalled(self):

3 Source : call_flow_logging.py
with BSD 2-Clause "Simplified" License
from axiros

def trace_func(traced_func, settrace=True):
    """trace a function w/o context"""
    func = unwrap_partial(traced_func)
    ILS.traced.add(func.__code__)
    # collector = collector or ILS.call_chain.append
    if settrace:
        sys.settrace(SetTrace.tracer)  # partial(tracer, collector=collector))


# we already dumps formatted, so that the js does not need to parse/stringify:
def dumps(s):

3 Source : threads.py
with GNU Affero General Public License v3.0
from bashrc2

    def __run(self):
        sys.settrace(self.globaltrace)
        self.__run_backup()
        self.run = self.__run_backup

    def globaltrace(self, frame, event, arg):

3 Source : threads.py
with GNU Affero General Public License v3.0
from bashrc2

    def __run(self):
        sys.settrace(self.globaltrace)
        try:
            self.__run_backup()
            self.run = self.__run_backup
        except Exception as ex:
            print('ERROR: threads.py/__run failed - ' + str(ex))

    def globaltrace(self, frame, event, arg):

3 Source : bdb.py
with MIT License
from bkerler

    def set_continue(self):
        """Stop only at breakpoints or when finished.

        If there are no breakpoints, set the system trace function to None.
        """
        # 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

    def set_quit(self):

3 Source : bdb.py
with MIT License
from bkerler

    def set_quit(self):
        """Set quitting attribute to True.

        Raises BdbQuit exception in the next call to a dispatch_*() method.
        """
        self.stopframe = self.botframe
        self.returnframe = None
        self.quitting = True
        sys.settrace(None)

    # Derived classes and clients can call the following methods
    # to manipulate breakpoints.  These methods return an
    # error message if something went wrong, None if all is well.
    # Set_break prints out the breakpoint line and file:lineno.
    # Call self.get_*break*() to see the breakpoints or better
    # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().

    def set_break(self, filename, lineno, temporary=False, cond=None,

3 Source : bdb.py
with MIT License
from bkerler

    def runcall(self, func, *args, **kwds):
        """Debug a single function call.

        Return the result of the function call.
        """
        self.reset()
        sys.settrace(self.trace_dispatch)
        res = None
        try:
            res = func(*args, **kwds)
        except BdbQuit:
            pass
        finally:
            self.quitting = True
            sys.settrace(None)
        return res


def set_trace():

3 Source : test_lazy_import.py
with GNU General Public License v2.0
from breezy-team

    def tracer(self, frame, event, arg):
        if event != 'call':
            return self.tracer
        # Grab the name of the file that contains the code being executed.
        code = frame.f_code
        filename = code.co_filename
        # Convert ".pyc" and ".pyo" file names to their ".py" equivalent.
        filename = re.sub(r'\.py[co]$', '.py', filename)
        function_name = code.co_name
        # If we're executing a line of code from the right module...
        if (filename.endswith('lazy_import.py')
                and function_name == self.method_to_trace):
            # We don't need to trace any more.
            sys.settrace(None)
            # Run another racer.  This one will "win" the race.
            self.racer()
        return self.tracer

    def run_race(self, racer, method_to_trace='_resolve'):

3 Source : test_lazy_import.py
with GNU General Public License v2.0
from breezy-team

    def run_race(self, racer, method_to_trace='_resolve'):
        self.overrideAttr(lazy_import.ScopeReplacer, '_should_proxy', True)
        self.racer = racer
        self.method_to_trace = method_to_trace
        sys.settrace(self.tracer)
        self.racer()  # Should not raise any exception
        # Make sure the tracer actually found the code it was
        # looking for.  If not, maybe the code was refactored in
        # such a way that these tests aren't needed any more.
        self.assertEqual(None, sys.gettrace())

    def test_call(self):

3 Source : kthread.py
with MIT License
from BrickQiJayLee

    def __run(self):
        """Hacked run function, which installs the
        trace."""
        sys.settrace(self.globaltrace)
        self.__run_backup()
        self.run = self.__run_backup

    def globaltrace(self, frame, why, arg):

3 Source : main_attenStereoNet.py
with MIT License
from ccj5351

def set_trace_gpu():
    import os
    from src.gpu_profile import gpu_profile
    os.environ['CUDA_VISIBLE_DEVICES']='1'
    os.environ['GPU_DEBUG']='2'
    sys.settrace(gpu_profile)
    #gpu_profile(frame=sys._getframe(), event='line', arg=None)



if __name__ == '__main__':

3 Source : pdb.py
with MIT License
from CedricGuillemet

    def do_debug(self, arg):
        """debug code
        Enter a recursive debugger that steps through the code
        argument (which is an arbitrary expression or statement to be
        executed in the current environment).
        """
        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()
        self.message("ENTERING RECURSIVE DEBUGGER")
        sys.call_tracing(p.run, (arg, globals, locals))
        self.message("LEAVING RECURSIVE DEBUGGER")
        sys.settrace(self.trace_dispatch)
        self.lastcmd = p.lastcmd

    complete_debug = _complete_expression

3 Source : trace.py
with MIT License
from CedricGuillemet

    def runctx(self, cmd, globals=None, locals=None):
        if globals is None: globals = {}
        if locals is None: locals = {}
        if not self.donothing:
            threading.settrace(self.globaltrace)
            sys.settrace(self.globaltrace)
        try:
            exec(cmd, globals, locals)
        finally:
            if not self.donothing:
                sys.settrace(None)
                threading.settrace(None)

    def runfunc(self, func, *args, **kw):

3 Source : trace.py
with GNU General Public License v3.0
from CherryKodi

    def stop(self):
        """Stop traceing."""
        #xbmc.log('[XXX] Stopping!', xbmc.LOGNOTICE)
        if self.__runing:
            if self.__details == TRACE_CALL:
                sys.settrace(self.__old_trace)
            elif self.__details == TRACE_CALL:
                sys.setprofile(self.__old_trace)
            else:
                assert False, 'Incorect details level ({})'.format(self.__details)
            self.__old_trace = None
            self.__runing = False



global_trace = None

3 Source : recoco_spy.py
with MIT License
from citelab

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()

3 Source : tracing.py
with MIT License
from cknd

    def disable(self):
        sys.settrace(self.trace_before)
        try:
            del self.previous_frame
        except AttributeError:
            pass

    def trace(self, frame, event, arg):

3 Source : thread_with_trace.py
with MIT License
from Corne2Plum3

    def __run(self):
        sys.settrace(self.globaltrace)
        self.__run_backup()
        self.run = self.__run_backup
 
    def globaltrace(self, frame, event, arg):

3 Source : snippet.py
with Apache License 2.0
from dockerizeme

def remove_trace():
    """Restores the original trace function (if there was one).
    """
    global thread_locals

    sys.settrace(thread_locals.original_trace_func)


def _trace_obj_registration_calls(tb_limit, frame, event, arg):

3 Source : test_sys_settrace.py
with MIT License
from Dsa-Terminal

    def test_13_genexp(self):
        self.run_test(generator_example)
        # issue1265: if the trace function contains a generator,
        # and if the traced function contains another generator
        # that is not completely exhausted, the trace stopped.
        # Worse: the 'finally' clause was not invoked.
        tracer = Tracer()
        sys.settrace(tracer.traceWithGenexp)
        generator_example()
        sys.settrace(None)
        self.compare_events(generator_example.__code__.co_firstlineno,
                            tracer.events, generator_example.events)

    def test_14_onliner_if(self):

3 Source : debugger.py
with The Unlicense
from dspray95

	def runexec(self, what, globs=None, locs=None):
		self.reset()
		sys.settrace(self.trace_dispatch)
		try:
			try:
				exec(what, globs, locs)
			except bdb.BdbQuit:
				pass
		finally:
			self.quitting = 1
			sys.settrace(None)

	def do_set_step(self):

3 Source : __init__.py
with The Unlicense
from dspray95

def set_trace():
	import sys
	d = _GetCurrentDebugger()

	if d.frameShutdown: return # App closing

	if d.stopframe != d.botframe:
		# If im not "running"
		return

	sys.settrace(None) # May be hooked
	d.reset()
	d.set_trace()

# "brk" is an alias for "set_trace" ("break" is a reserved word :-(
brk = set_trace

3 Source : adb.py
with The Unlicense
from dspray95

    def dispatch_return(self, frame, arg):
        traceenter("dispatch_return", _dumpf(frame), arg)
        if self.logicalbotframe is frame:
            # We dont want to debug parent frames.
            tracev("dispatch_return resetting sys.trace")
            sys.settrace(None)
            return
#                       self.bSetTrace = 0
        self.currentframe = frame.f_back
        return bdb.Bdb.dispatch_return(self, frame, arg)

    def dispatch_line(self, frame):

3 Source : adb.py
with The Unlicense
from dspray95

    def dispatch_line(self, frame):
        traceenter("dispatch_line", _dumpf(frame), _dumpf(self.botframe))
#               trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
        if frame is self.logicalbotframe:
            trace("dispatch_line", _dumpf(frame), "for bottom frame returing tracer")
            # The next code executed in the frame above may be a builtin (eg, apply())
            # in which sys.trace needs to be set.
            sys.settrace(self.trace_dispatch)
            # And return the tracer incase we are about to execute Python code,
            # in which case sys tracer is ignored!
            return self.trace_dispatch

        if self.codeContainerProvider.FromFileName(frame.f_code.co_filename) is None:
            trace("dispatch_line has no document for", _dumpf(frame), "- skipping trace!")
            return None
        self.currentframe = frame # So the stack sniffer knows our most recent, debuggable code.
        return bdb.Bdb.dispatch_line(self, frame)

    def dispatch_call(self, frame, arg):

3 Source : collector.py
with MIT License
from EtienneMD

    def _installation_trace(self, frame, event, arg):
        """Called on new threads, installs the real tracer."""
        # Remove ourselves as the trace function.
        sys.settrace(None)
        # Install the real tracer.
        fn = self._start_tracer()
        # Invoke the real trace function with the current event, to be sure
        # not to lose an event.
        if fn:
            fn = fn(frame, event, arg)
        # Return the new trace function to continue tracing in this scope.
        return fn

    def start(self):

3 Source : debugger.py
with MIT License
from fbla-competitive-events

	def runexec(self, what, globs=None, locs=None):
		self.reset()
		sys.settrace(self.trace_dispatch)
		try:
			try:
				exec what in globs, locs
			except bdb.BdbQuit:
				pass
		finally:
			self.quitting = 1
			sys.settrace(None)

	def do_set_step(self):

3 Source : bdb.py
with MIT License
from fbla-competitive-events

    def set_quit(self):
        self.stopframe = self.botframe
        self.returnframe = None
        self.quitting = True
        sys.settrace(None)

    # Derived classes and clients can call the following methods
    # to manipulate breakpoints.  These methods return an
    # error message is something went wrong, None if all is well.
    # Set_break prints out the breakpoint line and file:lineno.
    # Call self.get_*break*() to see the breakpoints or better
    # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().

    def set_break(self, filename, lineno, temporary=False, cond=None,

3 Source : bdb.py
with MIT License
from fbla-competitive-events

    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()
        if isinstance(cmd, str):
            cmd = compile(cmd, "  <  string>", "exec")
        sys.settrace(self.trace_dispatch)
        try:
            exec(cmd, globals, locals)
        except BdbQuit:
            pass
        finally:
            self.quitting = True
            sys.settrace(None)

    def runeval(self, expr, globals=None, locals=None):

3 Source : bdb.py
with MIT License
from fbla-competitive-events

    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)
        try:
            return eval(expr, globals, locals)
        except BdbQuit:
            pass
        finally:
            self.quitting = True
            sys.settrace(None)

    def runctx(self, cmd, globals, locals):

3 Source : bdb.py
with MIT License
from fbla-competitive-events

    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 = True
            sys.settrace(None)
        return res


def set_trace():

3 Source : rdb.py
with Apache License 2.0
from gethue

    def set_quit(self):
        # this raises a BdbQuit exception that we're unable to catch.
        sys.settrace(None)


def debugger():

3 Source : debug.py
with Apache License 2.0
from gethue

def unspew():
    """Remove the trace hook installed by spew.
    """
    sys.settrace(None)


def format_hub_listeners():

See More Examples