【发布时间】:2011-09-15 21:38:16
【问题描述】:
假设你在 Python 中有一个像这样的简单生成器:
更新:
def f(self):
customFunction_1(argList_1)
yield
customFunction_2(argList_2)
yield
customFunction_3(argList_3)
yield
...
我在另一个脚本中调用 f(),例如:
h=f()
while True:
try:
h.next()
sleep(2)
except KeyboardInterrupt:
##[TODO] tell the last line in f() that was executed
有没有办法可以完成上面的 [TODO] 部分?那就是知道在键盘中断发生之前执行的 f() 中的最后一行?
【问题讨论】: