擅长:python、mysql、java
<p>不,如果要避免死锁,就不能等待任务中同一个执行器的未来。在</p>
<p>在本例中,您只能返回future,然后递归地处理结果:</p>
<pre><code>import concurrent.futures
import time
e = concurrent.futures.ThreadPoolExecutor(max_workers=10)
def task(depth):
print 'started depth %d' % (depth, )
if depth > 10:
return depth
else:
f = e.submit(task, depth + 1)
return f
f = e.submit(task, 0)
while isinstance(f.result(), concurrent.futures.Future):
f = f.result()
print f.result()
</code></pre>
<p>但是,最好首先避免这种递归执行。在</p>