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


Python sys.breakpointhook方法代码示例

本文整理汇总了Python中sys.breakpointhook方法的典型用法代码示例。如果您正苦于以下问题:Python sys.breakpointhook方法的具体用法?Python sys.breakpointhook怎么用?Python sys.breakpointhook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.breakpointhook方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def __init__(self, dbgClient):
        self._dbgClient = dbgClient

        # Some informations about the thread
        self.isMainThread = False
        self.quitting = False
        self.id = -1
        self.name = ''

        self.tracePythonLibs(0)

        # Special handling of a recursion error
        self.skipFrames = 0

        self.isBroken = False
        self.cFrame = None

        # current frame we are at
        self.currentFrame = None

        # frames, where we want to stop or release debugger
        self.stopframe = None
        self.returnframe = None
        self.stop_everywhere = False

        self.__recursionDepth = -1
        self.setRecursionDepth(inspect.currentframe())

        # background task to periodicaly check for client interactions
        self.eventPollFlag = False
        self.timer = _thread.start_new_thread(self.__eventPollTimer, ())

        # provide a hook to perform a hard breakpoint
        # Use it like this:
        # if hasattr(sys, 'breakpoint): sys.breakpoint()
        sys.breakpoint = self.set_trace
        if sys.version_info[:2] >= (3, 7):
            sys.breakpointhook = self.set_trace 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:40,代码来源:base_cdm_dbg.py

示例2: install_breakpointhook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def install_breakpointhook():
    def custom_sitecustomize_breakpointhook(*args, **kwargs):
        import os
        hookname = os.getenv('PYTHONBREAKPOINT')
        if (
               hookname is not None 
               and len(hookname) > 0 
               and hasattr(sys, '__breakpointhook__')
               and sys.__breakpointhook__ != custom_sitecustomize_breakpointhook
            ):
            sys.__breakpointhook__(*args, **kwargs)
        else:
            sys.path.append(os.path.dirname(os.path.dirname(__file__)))
            import pydevd
            kwargs.setdefault('stop_at_frame', sys._getframe().f_back)
            pydevd.settrace(*args, **kwargs)

    if sys.version_info[0:2] >= (3, 7):
        # There are some choices on how to provide the breakpoint hook. Namely, we can provide a 
        # PYTHONBREAKPOINT which provides the import path for a method to be executed or we
        # can override sys.breakpointhook.
        # pydevd overrides sys.breakpointhook instead of providing an environment variable because
        # it's possible that the debugger starts the user program but is not available in the 
        # PYTHONPATH (and would thus fail to be imported if PYTHONBREAKPOINT was set to pydevd.settrace).
        # Note that the implementation still takes PYTHONBREAKPOINT in account (so, if it was provided
        # by someone else, it'd still work).
        sys.breakpointhook = custom_sitecustomize_breakpointhook
    else:
        if sys.version_info[0] >= 3:
            import builtins as __builtin__ # Py3
        else:
            import __builtin__

        # In older versions, breakpoint() isn't really available, so, install the hook directly
        # in the builtins.
        __builtin__.breakpoint = custom_sitecustomize_breakpointhook
        sys.__breakpointhook__ = custom_sitecustomize_breakpointhook

# Install the breakpoint hook at import time. 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:41,代码来源:sitecustomize.py

示例3: test_sys_breakpointhook_configure_and_unconfigure

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_sys_breakpointhook_configure_and_unconfigure(self, testdir, arg):
        """
        Test that sys.breakpointhook is set to the custom Pdb class once configured, test that
        hook is reset to system value once pytest has been unconfigured
        """
        testdir.makeconftest(
            """
            import sys
            from pytest import hookimpl
            from _pytest.debugging import pytestPDB

            def pytest_configure(config):
                config._cleanup.append(check_restored)

            def check_restored():
                assert sys.breakpointhook == sys.__breakpointhook__

            def test_check():
                assert sys.breakpointhook == pytestPDB.set_trace
        """
        )
        testdir.makepyfile(
            """
            def test_nothing(): pass
        """
        )
        args = (arg,) if arg else ()
        result = testdir.runpytest_subprocess(*args)
        result.stdout.fnmatch_lines(["*1 passed in *"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:31,代码来源:test_debugging.py

示例4: test_environ_custom_class

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_environ_custom_class(self, testdir, custom_debugger_hook, arg):
        testdir.makeconftest(
            """
            import os
            import sys

            os.environ['PYTHONBREAKPOINT'] = '_pytest._CustomDebugger.set_trace'

            def pytest_configure(config):
                config._cleanup.append(check_restored)

            def check_restored():
                assert sys.breakpointhook == sys.__breakpointhook__

            def test_check():
                import _pytest
                assert sys.breakpointhook is _pytest._CustomDebugger.set_trace
        """
        )
        testdir.makepyfile(
            """
            def test_nothing(): pass
        """
        )
        args = (arg,) if arg else ()
        result = testdir.runpytest_subprocess(*args)
        result.stdout.fnmatch_lines(["*1 passed in *"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:29,代码来源:test_debugging.py

示例5: _execute_prepared_user_code

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def _execute_prepared_user_code(self, statements, global_vars):
        try:
            sys.settrace(self._trace)
            if hasattr(sys, "breakpointhook"):
                old_breakpointhook = sys.breakpointhook
                sys.breakpointhook = self._breakpointhook

            return super()._execute_prepared_user_code(statements, global_vars)
        finally:
            sys.settrace(None)
            if hasattr(sys, "breakpointhook"):
                sys.breakpointhook = old_breakpointhook 
开发者ID:thonny,项目名称:thonny,代码行数:14,代码来源:backend.py

示例6: setUp

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def setUp(self):
        # These tests require a clean slate environment.  For example, if the
        # test suite is run with $PYTHONBREAKPOINT set to something else, it
        # will mess up these tests.  Similarly for sys.breakpointhook.
        # Cleaning the slate here means you can't use breakpoint() to debug
        # these tests, but I think that's okay.  Just use pdb.set_trace() if
        # you must.
        self.resources = ExitStack()
        self.addCleanup(self.resources.close)
        self.env = self.resources.enter_context(EnvironmentVarGuard())
        del self.env['PYTHONBREAKPOINT']
        self.resources.enter_context(
            swap_attr(sys, 'breakpointhook', sys.__breakpointhook__)) 
开发者ID:bkerler,项目名称:android_universal,代码行数:15,代码来源:test_builtin.py

示例7: test_breakpoint_with_breakpointhook_set

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_breakpoint_with_breakpointhook_set(self):
        my_breakpointhook = MagicMock()
        sys.breakpointhook = my_breakpointhook
        breakpoint()
        my_breakpointhook.assert_called_once_with() 
开发者ID:bkerler,项目名称:android_universal,代码行数:7,代码来源:test_builtin.py

示例8: test_breakpoint_with_breakpointhook_reset

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_breakpoint_with_breakpointhook_reset(self):
        my_breakpointhook = MagicMock()
        sys.breakpointhook = my_breakpointhook
        breakpoint()
        my_breakpointhook.assert_called_once_with()
        # Reset the hook and it will not be called again.
        sys.breakpointhook = sys.__breakpointhook__
        with patch('pdb.set_trace') as mock:
            breakpoint()
            mock.assert_called_once_with()
        my_breakpointhook.assert_called_once_with() 
开发者ID:bkerler,项目名称:android_universal,代码行数:13,代码来源:test_builtin.py

示例9: test_breakpoint_with_args_and_keywords

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_breakpoint_with_args_and_keywords(self):
        my_breakpointhook = MagicMock()
        sys.breakpointhook = my_breakpointhook
        breakpoint(1, 2, 3, four=4, five=5)
        my_breakpointhook.assert_called_once_with(1, 2, 3, four=4, five=5) 
开发者ID:bkerler,项目名称:android_universal,代码行数:7,代码来源:test_builtin.py

示例10: test_breakpoint_with_passthru_error

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_breakpoint_with_passthru_error(self):
        def my_breakpointhook():
            pass
        sys.breakpointhook = my_breakpointhook
        self.assertRaises(TypeError, breakpoint, 1, 2, 3, four=4, five=5) 
开发者ID:bkerler,项目名称:android_universal,代码行数:7,代码来源:test_builtin.py

示例11: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def __init__(self, storage, charm_dir, meta, model):

        super().__init__(self, None)

        self.charm_dir = charm_dir
        self.meta = meta
        self.model = model
        self._observers = []      # [(observer_path, method_name, parent_path, event_key)]
        self._observer = weakref.WeakValueDictionary()       # {observer_path: observer}
        self._objects = weakref.WeakValueDictionary()
        self._type_registry = {}  # {(parent_path, kind): cls}
        self._type_known = set()  # {cls}

        if isinstance(storage, (str, pathlib.Path)):
            logger.warning(
                "deprecated: Framework now takes a Storage not a path")
            storage = SQLiteStorage(storage)
        self._storage = storage

        # We can't use the higher-level StoredState because it relies on events.
        self.register_type(StoredStateData, None, StoredStateData.handle_kind)
        stored_handle = Handle(None, StoredStateData.handle_kind, '_stored')
        try:
            self._stored = self.load_snapshot(stored_handle)
        except NoSnapshotError:
            self._stored = StoredStateData(self, '_stored')
            self._stored['event_count'] = 0

        # Hook into builtin breakpoint, so if Python >= 3.7, devs will be able to just do
        # breakpoint(); if Python < 3.7, this doesn't affect anything
        sys.breakpointhook = self.breakpoint

        # Flag to indicate that we already presented the welcome message in a debugger breakpoint
        self._breakpoint_welcomed = False

        # Parse once the env var, which may be used multiple times later
        debug_at = os.environ.get('JUJU_DEBUG_AT')
        self._juju_debug_at = debug_at.split(',') if debug_at else () 
开发者ID:canonical,项目名称:operator,代码行数:40,代码来源:framework.py

示例12: test_builtin_breakpoint_hooked

# 需要导入模块: import sys [as 别名]
# 或者: from sys import breakpointhook [as 别名]
def test_builtin_breakpoint_hooked(self, fake_stderr):
        # Verify that the proper hook is set.
        with patch.dict(os.environ, {'JUJU_DEBUG_AT': 'all'}):
            self.create_framework()  # creating the framework setups the hook
        with patch('pdb.Pdb.set_trace') as mock:
            # Calling through sys, not breakpoint() directly, so we can run the
            # tests with Py < 3.7.
            sys.breakpointhook()
        self.assertEqual(mock.call_count, 1) 
开发者ID:canonical,项目名称:operator,代码行数:11,代码来源:test_framework.py


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