File: _debugger_case_terminate.py

package info (click to toggle)
pydevd 3.3.0%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,892 kB
  • sloc: python: 77,508; cpp: 1,869; sh: 368; makefile: 50; ansic: 4
file content (37 lines) | stat: -rw-r--r-- 1,207 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
import time
import subprocess
import sys
import os

if __name__ == '__main__':
    if 'launch-subprocesses' in sys.argv:
        n = int(sys.argv[-1])
        if n != 0:
            subprocess.Popen([sys.executable, __file__, 'launch-subprocesses', str(n - 1)])
        if hasattr(os, 'getppid'):
            print('%screated %s (child of %s)' % ('\t' * (4 - n), os.getpid(), os.getppid()))
        else:
            print('%screated %s' % ('\t' * (4 - n), os.getpid()))

    elif 'check-subprocesses' in sys.argv or 'check-subprocesses-ignore-pid' in sys.argv:
        # Recursively create a process tree such as:
        # - parent (this process)
        #    - p3
        #      - p2
        #        - p1
        #          - p0
        #    - p3
        #      - p2
        #        - p1
        #          - p0
        p0 = subprocess.Popen([sys.executable, __file__, 'launch-subprocesses', '3'])
        p1 = subprocess.Popen([sys.executable, __file__, 'launch-subprocesses', '3'])

        if 'check-subprocesses-ignore-pid' in sys.argv:
            import pydevd
            pydevd.add_dont_terminate_child_pid(p0.pid)

        print('created', os.getpid())

    while True:
        time.sleep(.1)