I've a piece of code that submits a task to a ThreadPoolExecutor which starts a Process. I've realised that in Python 3.8 that Process finished with exit code 0. But I've updated Python to the 3.9 version and this started to finishing with exit code 1! Even when the Process executes an empty task.
Here's a minimal example:
from multiprocessing import Process
from concurrent.futures import ThreadPoolExecutor
def some_task():
pass
def execute_error():
p = Process(target=some_task)
p.start()
p.join()
print(p.exitcode) # This is always 1 on a ThreadPoolExecutor!!!
executor = ThreadPoolExecutor(max_workers=4)
executor.submit(execute_error)
# execute_error() # IMPORTANT: this works correctly (exit 0)
My versions:
Ubuntu 21.04
Python 3.9.4
Note that if __execute_error is called outside the ThreadPoolExecutor it works correctly. Is there I am missing? Is this a Python 3.9 bug? Is there any workaround? Any kind of help would be really appreciated
ProcessPoolExecutoralways returns 0 as expected, onlyThreadPoolExecutoris affected.