The following program frequently raises a ProcessLookupError exception when calling proc.terminate():
```
import threading
import subprocess
import multiprocessing
proc = subprocess.Popen(["sh", "-c", "exit 0"])
q = multiprocessing.Queue()
def communicate_thread(proc):
proc.communicate()
t = threading.Thread(target=communicate_thread, args=(proc,))
t.start()
proc.terminate()
t.join()
```
I'm reproducing this with Python 3.8.2 on Arch Linux by saving the script and rapidly executing it like this:
$ bash -e -c "while true; do python3 test.py; done
The (unused) multiprocessing.Queue seems to play a role here because the problem vanishes when removing that one line. |