fork download
  1. import Queue, threading
  2.  
  3. q = Queue.Queue()
  4.  
  5. def fib(n):
  6. a, b = 0, 1
  7. for i in range(0, n):
  8. a, b = b, a + b
  9. q.put((n, a))
  10. return
  11.  
  12. numeros = [10, 20, 25]
  13.  
  14. for n in numeros:
  15. t = threading.Thread(target=fib, args = (n,))
  16. t.daemon = True
  17. t.start()
  18.  
  19. while not q.empty():
  20. n, f = q.get()
  21. print ("{0}: {1}".format(n, f))
  22.  
Success #stdin #stdout 0.01s 18336KB
stdin
Standard input is empty
stdout
10: 55
20: 6765
25: 75025