How to use the pydevd.SetupHolder function in pydevd

To help you get started, we’ve selected a few pydevd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabioz / PyDev.Debugger / tests_python / test_pydev_monkey.py View on Github external
def test_monkey(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0', 'protocol-quoted-line': True}
            check = '''C:\\bin\\python.exe -u -c connect(\\"127.0.0.1\\")'''
            debug_command = (
                'import sys; '
                'sys.path.insert(0, r\'%s\'); '
                "import pydevd; pydevd.PydevdCustomization.DEFAULT_PROTOCOL='quoted-line'; "
                "pydevd.settrace(host='127.0.0.1', port=0, suspend=False, "
                'trace_only_current_thread=False, patch_multiprocessing=True, access_token=None, client_access_token=None); '
                ''
                "from pydevd import SetupHolder; "
                "SetupHolder.setup = %s; "
                ''
                'connect("127.0.0.1")') % (pydev_src_dir, SetupHolder.setup)
            if sys.platform == "win32":
github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / tests_python / test_pydev_monkey.py View on Github external
def test_monkey(self):
        original = SetupHolder.setup

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = '''C:\\bin\\python.exe -u -c connect(\\"127.0.0.1\\")'''
            debug_command = (
                'import sys; '
                'sys.path.append(r\'%s\'); '
                "import pydevd; pydevd.settrace(host='127.0.0.1', port=0, suspend=False, "
                'trace_only_current_thread=False, patch_multiprocessing=True); '
                ''
                "from pydevd import SetupHolder; "
                "SetupHolder.setup = %s; "
                ''
                'connect("127.0.0.1")') % (pydev_src_dir, SetupHolder.setup)
            if sys.platform == "win32":
                debug_command = debug_command.replace('"', '\\"')
github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / _pydev_bundle / pydev_monkey.py View on Github external
if arg.rsplit('.')[-1] in ['zip', 'pyz', 'pyzw']:
                        log_debug('Executing a PyZip, returning')
                        return args
                    break

                new_args.append(args[0])
        else:
            log_debug("Process is not python, returning.")
            return args

        i = 1
        # Original args should be something as:
        # ['X:\\pysrc\\pydevd.py', '--multiprocess', '--print-in-debugger-startup',
        #  '--vm_type', 'python', '--client', '127.0.0.1', '--port', '56352', '--file', 'x:\\snippet1.py']
        from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv
        original = setup_to_argv(SetupHolder.setup) + ['--file']
        while i < len(args):
            if args[i] == '-m':
                # Always insert at pos == 1 (i.e.: pydevd "--module" --multiprocess ...)
                original.insert(1, '--module')
            else:
                if args[i].startswith('-'):
                    new_args.append(args[i])
                else:
                    break
            i += 1

        # Note: undoing https://github.com/Elizaveta239/PyDev.Debugger/commit/053c9d6b1b455530bca267e7419a9f63bf51cddf
        # (i >= len(args) instead of i < len(args))
        # in practice it'd raise an exception here and would return original args, which is not what we want... providing
        # a proper fix for https://youtrack.jetbrains.com/issue/PY-9767 elsewhere.
        if i < len(args) and _is_managed_arg(args[i]):  # no need to add pydevd twice
github microsoft / ptvsd / src / ptvsd / _vendored / pydevd / _pydev_bundle / pydev_monkey.py View on Github external
if arg.rsplit('.')[-1] in ['zip', 'pyz', 'pyzw']:
                        pydev_log.debug('Executing a PyZip, returning')
                        return args
                    break

                new_args.append(args[0])
        else:
            pydev_log.debug("Process is not python, returning.")
            return args

        i = 1
        # Original args should be something as:
        # ['X:\\pysrc\\pydevd.py', '--multiprocess', '--print-in-debugger-startup',
        #  '--vm_type', 'python', '--client', '127.0.0.1', '--port', '56352', '--file', 'x:\\snippet1.py']
        from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv
        original = setup_to_argv(_get_setup_updated_with_protocol(SetupHolder.setup)) + ['--file']
        while i < len(args):
            if args[i] == '-m':
                # Always insert at pos == 1 (i.e.: pydevd "--module" --multiprocess ...)
                original.insert(1, '--module')
            else:
                if args[i].startswith('-'):
                    new_args.append(args[i])
                else:
                    break
            i += 1

        # Note: undoing https://github.com/Elizaveta239/PyDev.Debugger/commit/053c9d6b1b455530bca267e7419a9f63bf51cddf
        # (i >= len(args) instead of i < len(args))
        # in practice it'd raise an exception here and would return original args, which is not what we want... providing
        # a proper fix for https://youtrack.jetbrains.com/issue/PY-9767 elsewhere.
        if i < len(args) and _is_managed_arg(args[i]):  # no need to add pydevd twice
github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / _pydev_bundle / pydev_monkey.py View on Github external
args = remove_quotes_from_args(args)

        from pydevd import SetupHolder
        new_args = []
        if len(args) == 0:
            return args

        if is_python(args[0]):
            ind_c = get_c_option_index(args)

            if ind_c != -1:
                host, port = _get_host_port()

                if port is not None:
                    new_args.extend(args)
                    new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup)
                    return quote_args(new_args)
            else:
                # Check for Python ZIP Applications and don't patch the args for them.
                # Assumes the first non `-` argument is what we need to check.
                # There's probably a better way to determine this but it works for most cases.
                continue_next = False
                for i in range(1, len(args)):
                    if continue_next:
                        continue_next = False
                        continue

                    arg = args[i]
                    if arg.startswith('-'):
                        # Skip the next arg too if this flag expects a value.
                        continue_next = arg in ['-m', '-W', '-X']
                        continue
github konstellation-io / science-toolkit / vscode / extensions / ms-python.python-2020.2.63072 / pythonFiles / lib / python / new_ptvsd / no_wheels / ptvsd / _vendored / pydevd / _pydev_bundle / pydev_monkey.py View on Github external
args = remove_quotes_from_args(args)

        from pydevd import SetupHolder
        new_args = []
        if len(args) == 0:
            return args

        if is_python(args[0]):
            ind_c = get_c_option_index(args)

            if ind_c != -1:
                host, port = _get_host_port()

                if port is not None:
                    new_args.extend(args)
                    new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup)
                    return quote_args(new_args)
            else:
                # Check for Python ZIP Applications and don't patch the args for them.
                # Assumes the first non `-` argument is what we need to check.
                # There's probably a better way to determine this but it works for most cases.
                continue_next = False
                for i in range(1, len(args)):
                    if continue_next:
                        continue_next = False
                        continue

                    arg = args[i]
                    if arg.startswith(_get_str_type_compatible(arg, '-')):
                        # Skip the next arg too if this flag expects a value.
                        continue_next = arg in _get_str_type_compatible(arg, ['-m', '-W', '-X'])
                        continue
github fabioz / PyDev.Debugger / pydevd.py View on Github external
def run(self):
            host = SetupHolder.setup['client']
            port = SetupHolder.setup['port']

            self._server_socket = create_server_socket(host=host, port=port)

            while not self.killReceived:
                try:
                    s = self._server_socket
                    if s is None:
                        return

                    s.listen(1)
                    new_socket, _addr = s.accept()
                    if self.killReceived:
                        pydev_log.info("Connection (from wait_for_attach) accepted but ignored as kill was already received.")
                        return

                    pydev_log.info("Connection (from wait_for_attach) accepted.")
github fabioz / PyDev.Debugger / _pydev_bundle / pydev_monkey.py View on Github external
args = remove_quotes_from_args(args)

        from pydevd import SetupHolder
        new_args = []
        if len(args) == 0:
            return args

        if is_python(args[0]):
            ind_c = get_c_option_index(args)

            if ind_c != -1:
                host, port = _get_host_port()

                if port is not None:
                    new_args.extend(args)
                    new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup)
                    return quote_args(new_args)
            else:
                # Check for Python ZIP Applications and don't patch the args for them.
                # Assumes the first non `-` argument is what we need to check.
                # There's probably a better way to determine this but it works for most cases.
                continue_next = False
                for i in range(1, len(args)):
                    if continue_next:
                        continue_next = False
                        continue

                    arg = args[i]
                    if arg.startswith('-'):
                        # Skip the next arg too if this flag expects a value.
                        continue_next = arg in ['-m', '-W', '-X']
                        continue
github microsoft / ptvsd / src / ptvsd / _vendored / pydevd / _pydev_bundle / pydev_monkey.py View on Github external
args = remove_quotes_from_args(args)

        from pydevd import SetupHolder
        new_args = []
        if len(args) == 0:
            return args

        if is_python(args[0]):
            ind_c = get_c_option_index(args)

            if ind_c != -1:
                host, port = _get_host_port()

                if port is not None:
                    new_args.extend(args)
                    new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup)
                    return quote_args(new_args)
            else:
                # Check for Python ZIP Applications and don't patch the args for them.
                # Assumes the first non `-` argument is what we need to check.
                # There's probably a better way to determine this but it works for most cases.
                continue_next = False
                for i in range(1, len(args)):
                    if continue_next:
                        continue_next = False
                        continue

                    arg = args[i]
                    if arg.startswith('-'):
                        # Skip the next arg too if this flag expects a value.
                        continue_next = arg in ['-m', '-W', '-X']
                        continue
github konstellation-io / science-toolkit / vscode / extensions / ms-python.python-2020.2.63072 / pythonFiles / lib / python / new_ptvsd / no_wheels / ptvsd / _vendored / pydevd / pydevd_attach_to_process / attach_script.py View on Github external
fix_main_thread_id(on_warn=on_warn, on_exception=on_exception, on_critical=on_critical)

        else:
            from _pydev_bundle import pydev_log  # @Reimport
            pydev_log.debug('The threading module is already imported by user code.')

        if protocol:
            from _pydevd_bundle import pydevd_defaults
            pydevd_defaults.PydevdCustomization.DEFAULT_PROTOCOL = protocol

        import pydevd

        # I.e.: disconnect/reset if already connected.

        pydevd.SetupHolder.setup = None

        py_db = pydevd.get_global_debugger()
        if py_db is not None:
            py_db.dispose_and_kill_all_pydevd_threads(wait=False)

        # pydevd.DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = True
        # pydevd.DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = 3
        # pydevd.DebugInfoHolder.DEBUG_TRACE_LEVEL = 3
        pydevd.settrace(
            port=port,
            host=host,
            stdoutToServer=True,
            stderrToServer=True,
            overwrite_prev_trace=True,
            suspend=False,
            trace_only_current_thread=False,