此defer非golang中的defer https://tour.golang.org/flowcontrol/12
from twitter.common.concurrent import Timeout, deadline, defer from twitter.common.quantity import Amount, Time import time def _stop(): print 'stop begin' time.sleep(7) print 'stop done' def stop(): defer(_stop) deadline(stop, timeout= Amount(3, Time.SECONDS), daemon=True, propagate=True)
这个代码是不会抛出exception的,twitter中defer主要用途是并发启动一些命令,不会相互block。
refer to: https://github.com/twitter/commons/tree/master/src/python/twitter/common/concurrent