title: using asyncio with MySQLdb
body: <p>I'm trying to understand <code>asyncio</code> and how to use it with MySQLdb. I think I just don't understand how asyncio works. For example, let's say I want to asynchronously do two queries at the same time. For example, without async and I'm doing two queries then I might do it like</p>
  
  <pre><code>import MySQLdb
  
  def test1():
      conn = MySQLdb.connect('host', 'user', 'password', 'db')
      conn.query('FIND * FROM table1')
      return conn.store_result().fetch_row(numrows=0, how=1)
      conn.close()
  
  def test1():
      conn = MySQLdb.connect('host', 'user', 'password', 'db')
      conn.query('FIND * FROM table2')
      return conn.store_result().fetch_row(numrows=0, how=1)
      conn.close()
  
  if __name__ == '__main__':
      foo1 = test1()
      foo2 = test2()
  </code></pre>
  
  <p>And this is slow because it needs to finish the query from <code>test1()</code> before even starting <code>test2()</code>. My understanding is that this is where <code>asyncio</code> helps because it can start a function and then let go control to do a second function. I thought you did this by making a function into an asynchronous function using <code>async</code> and then said where to wait in the function with <code>await</code>, but I'm pretty sure I'm misunderstanding that. This is what I am trying to do:</p>
  
  <pre><code>import asyncio
  import MySQLdb
  
  async def test1():
      conn = await MySQLdb.connect('host', 'user', 'password', 'db')
      await conn.query('FIND * FROM table1')
      conn.close()
      return conn.store_result().fetch_row(numrows=0, how=1)
  
  async def test1():
      conn = await MySQLdb.connect('host', 'user', 'password', 'db')
      await conn.query('FIND * FROM table2')
      conn.close()
      return conn.store_result().fetch_row(numrows=0, how=1)
  
  if __name__ == '__main__':
      loop = sayncio.get_event_loop()
      loop.run_until_complete(asyncio.gather(test1(), test2()))
      loop.close()
  </code></pre>
  
  <p>And this doesn't work. Is there a way to make asynchronous queries with MySQLdb in this way? I'm using Python 3.6.</p>