twitter.common.concurrent deadline and defer

2023-05-15,,

此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

twitter.common.concurrent deadline and defer的相关教程结束。

《twitter.common.concurrent deadline and defer.doc》

下载本文的Word格式文档,以方便收藏与打印。