I found your question interesting, so I found it.
I found the behavior of the .cancel() method as indicated in the python documentation. As for your simultaneous functions, unfortunately, they could not be undone even after they were told to do it. If my finding is correct, then I believe that Python really requires a more efficient .cancel () method.
Run the code below to check my details.
from concurrent.futures import ProcessPoolExecutor, as_completed from time import time
Update: You can force the completion of parallel processes through bash, but as a result, the main python program will also end. If this is not a problem with you, try the code below.
You must add the codes below between the last two print statements to see for yourself. Note. This code only works if you are not running any other python3 program.
import subprocess, os, signal result = subprocess.run(['ps', '-C', 'python3', '-o', 'pid='], stdout=subprocess.PIPE).stdout.decode('utf-8').split() print ('result =', result) for i in result: print('PID = ', i) if i != result[0]: os.kill(int(i), signal.SIGKILL) try: os.kill(int(i), 0) raise Exception("""wasn't able to kill the process HINT:use signal.SIGKILL or signal.SIGABORT""") except OSError as ex: continue
Sun bear
source share