#!/usr/local/bin/python # This is a really simple example of a coroutine def printmatcher(matchtext): while True: line = (yield) # Notice the use of (yield) as an expression if (matchtext in line): print matchtext + ": " + line matcher = printmatcher("Greg") matcher.next() # Advance to the first yield matcher.send("Sit, Greg, sit") # Send the string to the coroutine matcher.send("Watch Phil run") matcher.send("Hi there, Greg")