File: python_concurency_reproducer.py

package info (click to toggle)
socket-wrapper 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 788 kB
  • sloc: ansic: 13,079; sh: 65; python: 16; makefile: 13
file content (32 lines) | stat: -rwxr-xr-x 969 bytes parent folder | download
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
#!/usr/bin/env python3
"""
Simplified minimal reproducer for SOCKET_WRAPPER concurrency issue.
"""

import subprocess
import concurrent.futures


def run_subprocess():
    """Run a simple subprocess."""
    # Simple command that might trigger socket operations
    p = subprocess.Popen(['echo', 'test'],
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()
    return stdout.decode().strip()


def main():
    # Run multiple subprocesses in parallel using ProcessPoolExecutor. The pool
    # executor processes do fd passing over unix socket.
    with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
        futures = [executor.submit(run_subprocess) for _ in range(10)]

        for i, future in enumerate(concurrent.futures.as_completed(futures)):
            result = future.result()
            print(f"Task {i}: {result}")


if __name__ == '__main__':
    main()