use*_*646 -1 python function-call timestamping simultaneous-calls
我在模块中有一个读取功能.
如果我同时执行该功能,我需要为其加时间戳.
我该怎么做呢?
我会提供一个稍微不同的方法:
import time
def timestampit(func):
def decorate(*args, **kwargs):
decorate.timestamp = time.time()
return func(*args, **kwargs)
return decorate
@timestampit
def hello():
print 'hello'
hello()
print hello.timestamp
time.sleep(1)
hello()
print hello.timestamp
Run Code Online (Sandbox Code Playgroud)
与Swaroop示例的不同之处在于:
归档时间: |
|
查看次数: |
1262 次 |
最近记录: |