此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

相关文章:

  • 2022-02-18
  • 2022-02-28
  • 2021-08-01
  • 2021-09-04
  • 2022-12-23
  • 2021-10-10
  • 2021-10-10
猜你喜欢
  • 2022-01-02
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案