From http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/