title: How to use Python Concurrent Futures with decorators
body: <p>I'm using a decorator for the thread pool executor:</p>
  
  <pre><code>from functools import wraps
  from .bounded_pool_executor import BoundedThreadPoolExecutor
  
  _DEFAULT_POOL = BoundedThreadPoolExecutor(max_workers=5)
  
  def threadpool(f, executor=None):
      @wraps(f)
      def wrap(*args, **kwargs):
          return (executor or _DEFAULT_POOL).submit(f, *args, **kwargs)
  </code></pre>
  
  <p>where the <code>BoundedThreadPoolExecutor</code> is defined <a href="https://github.com/mowshon/bounded_pool_executor" rel="nofollow noreferrer">here</a> </p>
  
  <p>When I try to use the concurrent futures in a function decorated with <code>@threadpool</code> and then waiting all the futures with<code>as_completed</code> like</p>
  
  <pre><code>def get_results_as_completed(futures):
      # finished, pending = wait(futures, return_when=ALL_COMPLETED)
      futures_results = as_completed(futures)
      for f in futures_results:
          try:
              yield f.result()
          except:
              pass
  </code></pre>
  
  <p>for some worker defined like</p>
  
  <pre><code>from thread_support import threadpool
  from time import sleep
  from random import randint
  
  @threadpool
  def my_worker:
       res = {}
       # do something
       sleep(randint(1, 5))
       return res
  
  if __name__ == "__main__":
     futures_results = get_results_as_completed(futures)
         for r in futures_results:
             results.append(r)
  </code></pre>
  
  <p>I cannot get the futures completed despite of the <code>.result()</code> call, thus resulting in a infinite loop on futures_results. Why? </p>