在阅读了Pebble的文档(https://pythonhosted.org/Pebble/)之后,这似乎很简单。但是,我无法获得预期的结果。
我从他们网站上给出的例子开始
import time
from pebble import concurrent, ProcessExpired
from concurrent.futures import TimeoutError
@concurrent.process(timeout=10)
def function(foo, bar=0):
time.sleep(5)
return foo + bar
future = function(1, bar=2)
try:
result = future.result()
except TimeoutError as error:
print("function took longer than %d seconds" % error.args[1])
except ProcessExpired as error:
print("%s. Exit code: %d" % (error, error.exitcode))
except Exception as error:
print("function raised %s" % error)
print(error.traceback)
else:
print(str(result))
我的理解:
实际上,我从未获得理想的结果,而是显示消息“功能花费了10秒钟以上”。
您能告诉我我错过了什么才能获得预期的结果吗(即foo + bar)?