title: ThreadPool in Flask
body: <p>This is a piece of my code. I am asking if I can serve many clients without reaching any errors (because I have limited the processes in <code>2</code>)?</p>
  
  <pre><code>from multiprocessing.pool import ThreadPool
  
  pool = ThreadPool(processes=2)
  
  @app.route("/query/&lt;lng&gt;/&lt;lat&gt;/", methods=['GET', 'POST'])
  def query(lng,lat):
     t1 = pool.apply_async(queryA, (lng, lat ))
     t2 = pool.apply_async(queryB, (lng, lat ))
  
     results = {}
     results['a'] = t1.get()
     results['b'] = t2.get()
  
     return dumps(results)
  </code></pre>
  
  <p>I previously had the <code>pool = ThreadPool(processes=2)</code> inside the function but I got <code>error: can't start new thread</code>:</p>
  
  <pre><code>def query(lng,lat):
      pool = ThreadPool(processes=2)
      #rest
  </code></pre>
  
  <p>Therefore I would like to ask if I can serve more than 1 clients simultaneously without any errors? If no what is the correct code I should use?</p>
  
  <p>Is <code>pool</code> now global and if I have 2 simultaneous request I will hit the limit (2x2=4 running requests)? </p>