import threading, queue
def fibo(n):
a, b = 0, 1
for i in range(n):
a, b = b, a+b
data[threading.currentThread().getName()] = a
if(threading.active_count() == 2): # se só houverem 2 threads esta e a main
kill_sig.put(True)
data = {} # armazenar os dados
kill_sig = queue.Queue()
fibos = [10, 15, 20, 30]
for k, v in enumerate(fibos, 1):
t = threading.Thread(target=fibo, args=(v,), name='t_{}'.format(k)).start() # preparar cada thread e comecar trab
kill_sig.get() # bloquear aqui ate receber 'sinal'
print(data) # trabalho feito por cada thread
aW1wb3J0IHRocmVhZGluZywgcXVldWUKCmRlZiBmaWJvKG4pOgogICAgYSwgYiA9IDAsIDEKICAgIGZvciBpIGluIHJhbmdlKG4pOgogICAgICAgIGEsIGIgPSBiLCBhK2IKICAgIGRhdGFbdGhyZWFkaW5nLmN1cnJlbnRUaHJlYWQoKS5nZXROYW1lKCldID0gYQogICAgaWYodGhyZWFkaW5nLmFjdGl2ZV9jb3VudCgpID09IDIpOiAjIHNlIHPDsyBob3V2ZXJlbSAyIHRocmVhZHMgZXN0YSBlIGEgbWFpbgogICAgICAgIGtpbGxfc2lnLnB1dChUcnVlKQoKZGF0YSA9IHt9ICMgYXJtYXplbmFyIG9zIGRhZG9zCmtpbGxfc2lnID0gcXVldWUuUXVldWUoKQpmaWJvcyA9IFsxMCwgMTUsIDIwLCAzMF0KZm9yIGssIHYgaW4gZW51bWVyYXRlKGZpYm9zLCAxKToKICAgIHQgPSB0aHJlYWRpbmcuVGhyZWFkKHRhcmdldD1maWJvLCBhcmdzPSh2LCksIG5hbWU9J3Rfe30nLmZvcm1hdChrKSkuc3RhcnQoKSAjIHByZXBhcmFyIGNhZGEgdGhyZWFkIGUgY29tZWNhciB0cmFiCgpraWxsX3NpZy5nZXQoKSAjIGJsb3F1ZWFyIGFxdWkgYXRlIHJlY2ViZXIgJ3NpbmFsJwpwcmludChkYXRhKSAjIHRyYWJhbGhvIGZlaXRvIHBvciBjYWRhIHRocmVhZA==