title: FastAPI asynchronous background tasks blocks other requests?
body: <p>I want to run a simple background task in FastAPI, which involves some computation before dumping it into the database. However, the computation would block it from receiving any more requests.</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import BackgroundTasks, FastAPI
  
  app = FastAPI()
  db = Database()
  
  async def task(data):
      otherdata = await db.fetch(&quot;some sql&quot;)
      newdata = somelongcomputation(data,otherdata) # this blocks other requests
      await db.execute(&quot;some sql&quot;,newdata)
     
  
  
  @app.post(&quot;/profile&quot;)
  async def profile(data: Data, background_tasks: BackgroundTasks):
      background_tasks.add_task(task, data)
      return {}
  </code></pre>
  <p>What is the best way to solve this issue?</p>