我正在尝试使用python huey(https://github.com/coleifer/huey/blob/master/huey/api.py)来允许烧瓶使用任务队列。
从函数开始:
def some_long_calculation():
driver = create_chromedriver(True)
print(driver.capabilities['version'])
driver.get("https://www.yahoo.com/news/")
我将其导入task.py文件,并使用以下命令将其转换为任务函数:
from . import my_huey
some_long_calculation_task = my_huey.task(some_long_calculation)
然后我将some_long_calculation_task导入main / views.py并尝试使用:
@main.route('/sanity_check')
def sanity_check():
png = some_long_calculation_task()
return send_file(io.BytesIO(png),mimetype='image/png')
但是我得到了
traceback (most recent call last):
File "...lib\site-packages\flask\app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "...lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "...lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "...lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "...lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "...lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "...lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "...lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "...lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "...lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "...app\main\views.py", line 123, in sanity_check
png = some_long_calculation_task()
TypeError: decorator() missing 1 required positional argument: 'func'
>>> some_long_calculation_task
<function Huey.task.<locals>.decorator at 0x0000028CF8CF2BF8>
我该如何解决?
答案 0 :(得分:2)
根据错误消息,task
返回一个修饰符(通常与@
一起用作语法糖)。
请尝试以下代码:
from . import my_huey
some_long_calculation_task = my_huey.task()(some_long_calculation)
此中的“正常”用法类似于
@my_huey.task()
def my_function(...):
...