當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.getprofile方法代碼示例

本文整理匯總了Python中sys.getprofile方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.getprofile方法的具體用法?Python sys.getprofile怎麽用?Python sys.getprofile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sys的用法示例。


在下文中一共展示了sys.getprofile方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: restore_profiler

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def restore_profiler():
    """If a typechecking profiler is active, e.g. created by
    pytypes.set_global_typechecked_profiler(), such a profiler
    must be restored whenever a TypeCheckError is caught.
    The call must stem from the thread that raised the error.
    Otherwise the typechecking profiler is implicitly disabled.
    Alternatively one can turn pytypes into warning mode. In that
    mode no calls to this function are required (unless one uses
    filterwarnings("error") or likewise).
    """
    idn = threading.current_thread().ident
    if not sys.getprofile() is None:
        warn("restore_profiler: Current profile is not None!")
    if not idn in _saved_profilers:
        warn("restore_profiler: No saved profiler for calling thread!")
    else:
        sys.setprofile(_saved_profilers[idn])
        del _saved_profilers[idn] 
開發者ID:Stewori,項目名稱:pytypes,代碼行數:20,代碼來源:type_util.py

示例2: run

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [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

示例3: start

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def start(self):
        if self._active:
            raise RuntimeError('type checker already running')
        elif self._pending:
            raise RuntimeError('type checker already starting up')
        self._pending = True
        # Install this instance as the current profiler
        self._previous_profiler = sys.getprofile()
        self._set_caller_level_shift(0)
        sys.setprofile(self)

        # If requested, set this instance as the default profiler for all future threads
        # (does not affect existing threads)
        if self.all_threads:
            self._previous_thread_profiler = threading._profile_hook
            threading.setprofile(self)
        self._active, self._pending = True, False 
開發者ID:Stewori,項目名稱:pytypes,代碼行數:19,代碼來源:type_util.py

示例4: stop

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def stop(self):
        if self._active and not self._pending:
            self._pending = True
            if sys.getprofile() is self:
                sys.setprofile(self._previous_profiler)
                if not self._previous_profiler is None and \
                        isinstance(self._previous_profiler, TypeAgent):
                    self._previous_profiler._set_caller_level_shift(0)
            else:
                if sys.getprofile() is not None or not self._cleared:
                    warn('the system profiling hook has changed unexpectedly')
            if self.all_threads:
                if threading._profile_hook is self:
                    threading.setprofile(self._previous_thread_profiler)
                else:  # pragma: no cover
                    warn('the threading profiling hook has changed unexpectedly')
            self._active, self._pending = False, False 
開發者ID:Stewori,項目名稱:pytypes,代碼行數:19,代碼來源:type_util.py

示例5: test_empty

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_sys_setprofile.py

示例6: test_setget

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_sys_setprofile.py

示例7: test_setprofile

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def test_setprofile():
    profiler = TracingProfiler()
    assert sys.getprofile() is None
    with profiler:
        assert sys.getprofile() == profiler._profile
    assert sys.getprofile() is None
    sys.setprofile(lambda *x: x)
    with pytest.raises(RuntimeError):
        profiler.start()
    sys.setprofile(None) 
開發者ID:what-studio,項目名稱:profiling,代碼行數:12,代碼來源:test_tracing.py

示例8: stop

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def stop(self):
        """
        Removes the module profiler globally and from future threads.
        """
        if sys.getprofile() != self.profiler:
            logger.warning(
                "ModuleProfiler: The currently enabled profile function was not ours - unbinding anyways"
            )
        threading.setprofile(None)
        sys.setprofile(None) 
開發者ID:varietywalls,項目名稱:variety,代碼行數:12,代碼來源:Util.py

示例9: test_empty

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def test_empty(self):
        assert sys.getprofile() == None 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:4,代碼來源:test_profilehooks.py

示例10: test_setget

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import getprofile [as 別名]
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        assert sys.getprofile() == fn 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:8,代碼來源:test_profilehooks.py


注:本文中的sys.getprofile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。