title: Converting a Python function with a callback to an asyncio awaitable
body: <p>I want to use the <code>PyAudio</code> library in an async context, but the main entry point for the library only has a callback-based API:</p>
  
  <pre><code>import pyaudio
  
  def callback(in_data, frame_count, time_info, status):
      # Do something with data
  
  pa = pyaudio.PyAudio()
  self.stream = self.pa.open(
      stream_callback=callback
  )
  </code></pre>
  
  <p>How I'm hoping to use it is something like this:</p>
  
  <pre><code>pa = SOME_ASYNC_COROUTINE()
  async def listen():
      async for block in pa:
          # Do something with block
  </code></pre>
  
  <p>The problem is, I'm not sure how to convert this callback syntax to a future that completes when the callback fires. In JavaScript I would use <a href="http://bluebirdjs.com/docs/api/promise.promisify.html" rel="noreferrer"><code>promise.promisify()</code></a>, but Python doesn't seem to have anything like that.</p>