text: #!/usr/bin/env python
  # -*- coding:UTF-8 -*-
  #
  # cothread.py
  #
  # A thread object that runs a coroutine inside it.  Messages get sent
  # via a Queue object
  
  from threading import Thread
  from Queue import Queue
  from coroutine import *
  
  @coroutine
  def threaded(target):
      messages = Queue()
      def run_target():
          while True:
              item = messages.get()
              if item is GeneratorExit:
                  target.close()
                  return
              else:
                  target.send(item)
      Thread(target=run_target).start() # 子线程包裹一系列协程
      try:
          while True: # 父子线程通信靠的queue
              item = (yield)
              messages.put(item)
      except GeneratorExit:
          messages.put(GeneratorExit)
  
  # Example use
  
  if __name__ == '__main__':
      import xml.sax
      from cosax import EventHandler
      from buses import *
  
      xml.sax.parse("allroutes.xml", EventHandler(
                      buses_to_dicts(
                      threaded(
                           filter_on_field("route","22",
                           filter_on_field("direction","North Bound",
                           bus_locations()))
                      ))))
                   
  