from concurrent.futures import ThreadPoolExecutor, as_completed
def fib(n):
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return ((n, a))
numeros = [10, 20, 25]
with ThreadPoolExecutor(max_workers=5) as executor:
fibSubmit = {executor.submit(fib, n,): n for n in numeros}
for future in as_completed(fibSubmit):
try:
n, f = future.result()
except Exception as exc:
print("Erro! {0}".format(exc))
else:
print ("{0}: {1}".format(n, f))
ZnJvbSBjb25jdXJyZW50LmZ1dHVyZXMgaW1wb3J0IFRocmVhZFBvb2xFeGVjdXRvciwgYXNfY29tcGxldGVkCgpkZWYgZmliKG4pOgogICAgYSwgYiA9IDAsIDEKICAgIGZvciBpIGluIHJhbmdlKDAsIG4pOgogICAgICAgIGEsIGIgPSBiLCBhICsgYgogICAgcmV0dXJuICgobiwgYSkpCgpudW1lcm9zID0gWzEwLCAyMCwgMjVdCiAKd2l0aCBUaHJlYWRQb29sRXhlY3V0b3IobWF4X3dvcmtlcnM9NSkgYXMgZXhlY3V0b3I6CglmaWJTdWJtaXQgPSB7ZXhlY3V0b3Iuc3VibWl0KGZpYiwgbiwpOiBuIGZvciBuIGluIG51bWVyb3N9CgkKCWZvciBmdXR1cmUgaW4gYXNfY29tcGxldGVkKGZpYlN1Ym1pdCk6CgkJdHJ5OgoJCQluLCBmID0gZnV0dXJlLnJlc3VsdCgpCgkJZXhjZXB0IEV4Y2VwdGlvbiBhcyBleGM6CgkJCXByaW50KCJFcnJvISB7MH0iLmZvcm1hdChleGMpKQoJCWVsc2U6CgkJCXByaW50ICgiezB9OiB7MX0iLmZvcm1hdChuLCBmKSk=