title: Python - How can I make this code asynchronous?
body: <p>Here's some code that illustrates my problem:</p>
  
  <pre><code>def blocking1():
      while True:
          yield 'first blocking function example'
  
  def blocking2():
      while True:
          yield 'second blocking function example'
  
  for i in blocking1():
      print 'this will be shown'
  
  for i in blocking2():
      print 'this will not be shown'
  </code></pre>
  
  <p>I have two functions which contain <code>while True</code> loops. These will yield data which I will then log somewhere (most likely, to an sqlite database).</p>
  
  <p>I've been playing around with threading and have gotten it working. However, I don't really like it... What I would like to do is make my blocking functions asynchronous. Something like:</p>
  
  <pre><code>def blocking1(callback):
      while True:
          callback('first blocking function example')
  
  def blocking2(callback):
      while True:
          callback('second blocking function example')
  
  def log(data):
      print data
  
  blocking1(log)
  blocking2(log)
  </code></pre>
  
  <p>How can I achieve this in Python? I've seen the standard library comes with asyncore and the big name in this game is Twisted but both of these seem to be used for socket IO.</p>
  
  <p>How can I async my non-socket related, blocking functions?</p>