Python sys.getprofile() Examples

The following are 30 code examples of sys.getprofile(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sys , or try the search function .
Example #1
Source File: test_sys_setprofile.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #2
Source File: test_sys_setprofile.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #3
Source File: __init__.py    From profiling with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #4
Source File: type_util.py    From pytypes with Apache License 2.0 6 votes vote down vote up
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 
Example #5
Source File: type_util.py    From pytypes with Apache License 2.0 6 votes vote down vote up
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 
Example #6
Source File: type_util.py    From pytypes with Apache License 2.0 6 votes vote down vote up
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] 
Example #7
Source File: test_profilehooks.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        assert sys.getprofile() == fn 
Example #8
Source File: test_profilehooks.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        assert sys.getprofile() == None 
Example #9
Source File: test_sys_setprofile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #10
Source File: test_sys_setprofile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #11
Source File: test_sys_setprofile.py    From android_universal with MIT License 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #12
Source File: test_sys_setprofile.py    From android_universal with MIT License 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #13
Source File: test_profilehooks.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        assert sys.getprofile() == fn 
Example #14
Source File: test_profilehooks.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        assert sys.getprofile() == None 
Example #15
Source File: test_sys_setprofile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #16
Source File: test_sys_setprofile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #17
Source File: test_sys_setprofile.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #18
Source File: test_sys_setprofile.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #19
Source File: Util.py    From variety with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #20
Source File: test_sys_setprofile.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #21
Source File: test_sys_setprofile.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #22
Source File: test_sys_setprofile.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #23
Source File: test_sys_setprofile.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #24
Source File: test_sys_setprofile.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #25
Source File: test_sys_setprofile.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #26
Source File: test_tracing.py    From profiling with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #27
Source File: test_sys_setprofile.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #28
Source File: test_sys_setprofile.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile()) 
Example #29
Source File: test_sys_setprofile.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_setget(self):
        def fn(*args):
            pass

        sys.setprofile(fn)
        self.assertIs(sys.getprofile(), fn) 
Example #30
Source File: test_sys_setprofile.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_empty(self):
        self.assertIsNone(sys.getprofile())