Python文档提供了使用ThreadPoolExecutor进行死锁的示例代码: https://docs.python.org/3.8/library/concurrent.futures.html#threadpoolexecutor
from concurrent.futures import ThreadPoolExecutor
def wait_on_future():
f = executor.submit(pow,5,2)
# This will never complete because there is only one worker thread and
# it is executing this function.
print(f.result())
executor = ThreadPoolExecutor(max_workers=1)
executor.submit(wait_on_future)
可以将ThreadPoolExecutor修改为处理嵌套无死锁的情况吗?还是有一些其他语言的示例可以正确处理类似情况?
一种可能的解决方案可能是在提交嵌套任务之前将线程池工作者数增加1,然后在完成嵌套任务后再次将其减少。