title: Making Synchronous Flask Asynchronous - Flask Instances
body: <p>Normally when people talk about &quot;async&quot; or &quot;making Flask async&quot;, they refer to situations where Flask is monkey-patched with some async-tool (GEvent, asyncio, etc.)</p>
  <p>Considering that Flask is small enough to be &quot;created on the fly&quot;, I thought that this model might work:</p>
  <blockquote>
  <p>Incoming HTTP requests -&gt; HTTP server (eg. nginx/apache) -&gt;
  HTTP-request-queue -&gt; Flask instance (to handle each request)</p>
  </blockquote>
  <p>Without modifying any of your code, doing any monkey-patches, you essentially get your blocking code to be processed in isolation. After some digging, I believe it can be done:</p>
  <p><a href="http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#twisted-web%5D%5B1%5D" rel="nofollow noreferrer">http://flask.pocoo.org/docs/0.11/deploying/wsgi-standalone/#twisted-web][1]</a></p>
  <p>My questions are:</p>
  <ol>
  <li><p>Is using this approach less efficient than writing event-driven code? (eg. using GEvent or Tornado)</p>
  </li>
  <li><p>What is the model of how [1] is handling the requests? (is it the same as I described above)</p>
  </li>
  <li><p>Can a race-condition exist? Eg.</p>
  <blockquote>
  <p>Making 2 calls to a database where last HTTP request (request-2) is processed first (due to async request-processing), causing a conflict for the first HTTP request (request-1)</p>
  </blockquote>
  </li>
  </ol>