當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。