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


Python threading.settrace方法代码示例

本文整理汇总了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)
            """) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_threading.py

示例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 
开发者ID:ionelmc,项目名称:python-hunter,代码行数:27,代码来源:tracer.py

示例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 
开发者ID:ionelmc,项目名称:python-hunter,代码行数:18,代码来源:tracer.py

示例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 
开发者ID:guohuadeng,项目名称:odoo13-x64,代码行数:24,代码来源:trace.py

示例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 
开发者ID:mrknow,项目名称:filmkodi,代码行数:27,代码来源:pydevd.py

示例6: _unsettrace

# 需要导入模块: import threading [as 别名]
# 或者: from threading import settrace [as 别名]
def _unsettrace():
        sys.settrace(None) 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:trace.py

示例7: _settrace

# 需要导入模块: import threading [as 别名]
# 或者: from threading import settrace [as 别名]
def _settrace(func):
        threading.settrace(func)
        sys.settrace(func) 
开发者ID:glmcdona,项目名称:meddle,代码行数:5,代码来源:trace.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:14,代码来源:trace.py

示例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 
开发者ID:glmcdona,项目名称:meddle,代码行数:12,代码来源:trace.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_threading.py

示例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) 
开发者ID:ComparativeGenomicsToolkit,项目名称:Comparative-Annotation-Toolkit,代码行数:7,代码来源:trace.py

示例12: disable

# 需要导入模块: import threading [as 别名]
# 或者: from threading import settrace [as 别名]
def disable(self):
        """disable logging on all threads."""
        sys.settrace(None)
        threading.settrace(None) 
开发者ID:ComparativeGenomicsToolkit,项目名称:Comparative-Annotation-Toolkit,代码行数:6,代码来源:trace.py


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