title: How to make uWSGI main thread not serve requests for the Django web application?
body: <p>In my Django application, in the <code>__init__.py</code>, I have a class which spins up an event loop.</p>
  <pre><code>class X:
    def __init__(self):
      self.__loop = asyncio.get_event_loop()
  
    async def foo(self):
      ...
  
    def do_stuff(self):
      # some logic here
      self.__loop.run_until_complete(foo())
  </code></pre>
  <p>In the <code>__init__.py</code> I just have</p>
  <pre><code>x = X()
  </code></pre>
  <p>In my Django views, I do</p>
  <pre><code>from myapp import x
  
  def example_view(request):
    result = x.do_stuff()
    return JsonResponse({&quot;result&quot;: result})
  </code></pre>
  <p>But the problem is that with uWSGI, if the thread that serves the request is same as that was used during initialization, I get the Django's <code>SynchronousOnlyOperation</code> exception as it detects a running event loop in that particular thread.</p>
  <p>So my question is, is there a way not to use that initializing thread for serving requests or some other alternative to fix this issue?</p>
  <p>uwSGI is configured to run multiple processes and multiple threads, with <code>--enable-threads</code></p>