title: How do I perform async operations in a aiohttp request handler after sending the response?
body: <p>I want to perform async operations in a aiohttp request handler after sending the response. As <a href="https://aiohttp.readthedocs.io/en/stable/faq.html#how-do-i-perform-operations-in-a-request-handler-after-sending-the-response" rel="nofollow noreferrer">per docs</a> I should write</p>
  
  <pre class="lang-py prettyprint-override"><code>async def ping_handler(request):
      """Send PONG and increase DB counter."""
  
      # explicitly send the response
      resp = web.json_response({'message': 'PONG'})
      await resp.prepare(request)
      await resp.write_eof()
  
      # job after sending resp
      time.sleep(1)
  
      return resp
  </code></pre>
  
  <p>This recipe works great for non-async functions. But when I use <code>asyncio.sleep</code>, it failes:</p>
  
  <pre class="lang-py prettyprint-override"><code>async def ping_handler(request):
      """Send PONG and increase DB counter."""
  
      # explicitly send the response
      resp = web.json_response({'message': 'PONG'})
      await resp.prepare(request)
      await resp.write_eof()
  
      # job after sending resp
      print('Enter job')
      await asyncio.sleep(1)
      print('Exit job')
  
      return resp
  </code></pre>
  
  <p>I see <code>Enter job</code>, but no <code>Exit job</code>.</p>
  
  <p>What do I do wrong?</p>