|
3 | 3 | import argparse |
4 | 4 | import io |
5 | 5 | import os |
| 6 | +import shutil |
6 | 7 | import signal |
7 | 8 | import subprocess |
8 | 9 | import sys |
@@ -85,12 +86,11 @@ def reader(): |
85 | 86 | return result[0] |
86 | 87 |
|
87 | 88 |
|
88 | | -def _wait_for_process_exec(proc, name, timeout): |
| 89 | +def _wait_for_process_exec(proc, executable, timeout): |
89 | 90 | # Wait until a child process calls exec() to replace the forked process |
90 | 91 | # executable. Raise AssertionError on timeout. |
91 | 92 | for _ in sleeping_retry(timeout, max_delay=0.1): |
92 | | - exe = os.readlink(f"/proc/{proc.pid}/exe") |
93 | | - if os.path.basename(exe) == name: |
| 93 | + if os.path.samefile(f"/proc/{proc.pid}/exe", executable): |
94 | 94 | break |
95 | 95 |
|
96 | 96 |
|
@@ -617,15 +617,18 @@ def test_is_python_process_python_subprocess(self): |
617 | 617 | @unittest.skipUnless(sys.platform == "linux", "Linux only test") |
618 | 618 | def test_is_python_process_non_python_subprocess(self): |
619 | 619 | """Test that a non-Python subprocess is not detected as Python.""" |
| 620 | + executable = shutil.which("sleep") |
| 621 | + if executable is None: |
| 622 | + self.skipTest("sleep command not found") |
620 | 623 | # Start a non-Python subprocess (sleep command) |
621 | 624 | proc = subprocess.Popen( |
622 | | - ["sleep", "60"], |
| 625 | + [executable, "60"], |
623 | 626 | stdout=subprocess.DEVNULL, |
624 | 627 | stderr=subprocess.DEVNULL, |
625 | 628 | ) |
626 | 629 |
|
627 | 630 | try: |
628 | | - _wait_for_process_exec(proc, "sleep", SHORT_TIMEOUT) |
| 631 | + _wait_for_process_exec(proc, executable, SHORT_TIMEOUT) |
629 | 632 |
|
630 | 633 | self.assertFalse( |
631 | 634 | is_python_process(proc.pid), |
|
0 commit comments