title: Asyncio (Quart) throwing Task attached to a different loop error when connecting to MongoDB with motor
body: <p>I have created a webapp with Quart using MongoDB and using Motor.Asyncio. 
  When the app attempts to query the DB an error is thrown:</p>
  
  <pre><code>Task &lt;Task pending coro=&lt;ASGIHTTPConnection.handle_request() 
  running at /home/user/.local/lib/python3.7/site-packages/quart
  /asgi.py:59&gt; cb=[_wait.&lt;locals&gt;._on_completion() at /usr/lib/python3.7
  /asyncio/tasks.py:440]&gt; got Future &lt;Future pending cb=[run_on_executor.
  &lt;locals&gt;._call_check_cancel() at /home/user/.local/lib/python3.7/site-
  packages/motor/frameworks/asyncio/__init__.py:80]&gt; attached to a 
  different loop
  </code></pre>
  
  <p>I don't understand why this is occurring or have no idea how solve it.</p>
  
  <p>The app had been running without issue, but I decided to upgrade from Python 3.6 (on Ubuntu-18.04) to python 3.7.1. With this I upgraded Quart to 0.9.0. As a result of this upgrade the above error occurred.</p>
  
  <p>The app run from the command line with Hypercorn and Nginx.</p>
  
  <p>I'm not sure what portions of my code are relevant is this case</p>
  
  <p>I import Quart first then Motor:</p>
  
  <pre><code>    # Mongodb / Gridfs with Motor
      import motor.motor_asyncio
      from pymongo import ReturnDocument
      from bson.objectid import ObjectId
      from bson.son import SON
  
      client = motor.motor_asyncio.AsyncIOMotorClient()
      db = client.myDataBase
      fs = motor.motor_asyncio.AsyncIOMotorGridFSBucket(db)
  </code></pre>
  
  <p>After this I add:</p>
  
  <pre><code>    app = Quart(__name__)
  </code></pre>
  
  <p>I have tried moving this before the motor import block it has changed nothing.</p>
  
  <p>As suggested in the question/answer:
  <a href="https://stackoverflow.com/questions/41584243/runtimeerror-task-attached-to-a-different-loop">RuntimeError: Task attached to a different loop</a>
  I added:</p>
  
  <pre><code>    loop=asyncio.new_event_loop()
      asyncio.set_event_loop(loop)
      client = motor.motor_asyncio.AsyncIOMotorClient(io_loop=loop)
  </code></pre>
  
  <p>That did not solve it.</p>
  
  <p>This is the block were the first call to motor is made, and where the error occurs:</p>
  
  <pre><code>    try:
          session_info = await db.sessions.find_one(
              {
                  'session_id': uuid.UUID(session_id)
              },
              {
                  'username':True,
                  '_id':False
              }
          )
      except Exception as e:
          print('error retrieving session info:', e)
  </code></pre>
  
  <p>I can ignore the error and proceed, but then the next call is made and same error occurs.</p>
  
  <p>I understand that Quart works on the default event_loop and there should be no need to create a special loop for motor. It work without out it in the previous version. So I am at complete loss.</p>