def compute(n, task=None): import time yield task.sleep(n) raise StopIteration(time.asctime()) # result of 'compute' is current time