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


Python sys.setprofile方法代码示例

本文整理汇总了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) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:24,代码来源:base_cdm_dbg.py

示例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) 
开发者ID:what-studio,项目名称:profiling,代码行数:21,代码来源:utils.py

示例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 
开发者ID:what-studio,项目名称:profiling,代码行数:18,代码来源:__init__.py

示例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 
开发者ID:what-studio,项目名称:profiling,代码行数:24,代码来源:test_sampling.py

示例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) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:18,代码来源:profiler.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_sys.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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:threading.py

示例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 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:10,代码来源:clientbase_cdm_dbg.py

示例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 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:43,代码来源:clientbase_cdm_dbg.py

示例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) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:16,代码来源:base_cdm_dbg.py

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

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

示例13: setprofile

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

示例14: setUp

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def setUp(self):
        sys.setprofile(None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_sys_setprofile.py

示例15: tearDown

# 需要导入模块: import sys [as 别名]
# 或者: from sys import setprofile [as 别名]
def tearDown(self):
        sys.setprofile(None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_sys_setprofile.py


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