title: uWSGI thread has existing running event loop which causes Django's SynchronousOnlyOperation exception
body: <p>I have two Django views,</p>
  <pre><code>def view_that_accesses_orm(request): # say end point /useorm
    user = User.objects.first()
    ...
  </code></pre>
  <p>and</p>
  <pre><code>def view_that_creates_event_loop(request): # say endpoint /createloop
    client = AsycProvider()
    ... # do stuff with client
  </code></pre>
  <p>and <code>AsyncProvider</code> is something like</p>
  <pre><code>class AsyncProvider:
    def __init__(self):
      try:
        self.__loop = asyncio.get_event_loop()
      except RuntimeError as e:
        print(e) #no running event loop
        self.__loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.__loop)
      self.__session = aiohttp.ClientSession(loop=self.__loop)
  
    ... # other operations with asyncio.run_until_complete, asyncio.gather, and self.__session
  </code></pre>
  <p>Now the issue is that say if I have 1 process in uWSGI and 2 threads. Then they will be in a round robin fashion serving requests.</p>
  <p>So scenario is:</p>
  <ol>
  <li>User hits <code>/createloop</code> (given thread 1)</li>
  <li>User hits <code>/useorm</code> (given thread 2)</li>
  <li>User again hits <code>/useorm</code> (given thread 1)</li>
  </ol>
  <p>Now in third scenario, sometimes the event loop is running and since Django 3.x detects a running event loop and disallows us to access ORM, I get the <code>django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.</code> exception.</p>
  <p>I am not sure how the event loop doesn't stop and persist in the thread.</p>
  <p>Please explain what exactly could be the cause of this and what should be the fix?</p>