File: _debugger_case_pydevd_customization.py

package info (click to toggle)
pydevd 2.9.5%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,880 kB
  • sloc: python: 75,138; cpp: 1,851; sh: 310; makefile: 40; ansic: 4
file content (62 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import os


def main():
    env = os.environ.copy()
    pythonpath = env.get('PYTHONPATH', '')
    env['PYTHONPATH'] = os.path.dirname(__file__) + os.pathsep + \
        os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

    import pydevd
    if '--use-dap-mode' in sys.argv:
        pydevd.config('http_json', 'debugpy-dap')

    from _pydev_bundle import pydev_log
    pydev_log.debug('Argv received: %s', sys.argv)
    port = int(sys.argv[1])
    print('before pydevd.settrace')
    pydevd.settrace(port=port, patch_multiprocessing=True, suspend=True)
    print('after pydevd.settrace')

    import subprocess
    if '--use-c-switch' in sys.argv:
        child_process = subprocess.Popen(
            [sys.executable, '-u', '-c', 'import _debugger_case_pydevd_customization;_debugger_case_pydevd_customization.call()'],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=env,
        )
    elif '--posix-spawn' in sys.argv:
        env = os.environ.copy()
        args = ['-u', '_debugger_case_pydevd_customization.py', '--simple-call']
        pid = os.posix_spawn(sys.executable, args, env)
        os.waitpid(pid, 0)
        child_process = None  # We don't really have a subprocess.Popen instance in this case.
    else:
        child_process = subprocess.Popen(
            [sys.executable, '-u', '_debugger_case_pydevd_customization.py', '--simple-call'],
            cwd=os.path.dirname(__file__),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=env,
        )

    if child_process:
        stdout, stderr = child_process.communicate()
        assert b'called' in stdout, 'Did not find b"called" in stdout:\n>>%s<<\nstderr:\n>>%s<<\n' % (stdout, stderr)
    print('TEST SUCEEDED!')  # break 2 here


def call():
    import pydevd
    from _pydevd_bundle.pydevd_api import PyDevdAPI
    assert pydevd.get_global_debugger().get_arg_ppid() == PyDevdAPI().get_ppid()
    print("called")  # break 1 here


if __name__ == '__main__':
    if '--simple-call' in sys.argv:
        call()
    else:
        main()