我正在尝试使用 python huey ( https://github.com/coleifer/huey/blob/master/huey/api.py ) 来允许使用带有烧瓶的任务队列。
从文件 app.tasking.tasks 开始:
from . import my_huey
from app.main.cl import dummy_create_cl_listing, create_cl_listing
from app.main.mobiletest import some_long_calculation,create_chromedriver
create_cl_listing_task = my_huey.task()(create_cl_listing)
some_long_calculation_task = my_huey.task()(some_long_calculation)
@my_huey.task()
def dummy_create_task(messages):
time.sleep(5)
print('continuing..')
time.sleep(25)
return 'fin'
如果我运行:
$ python ...huey_consumer.exe run_huey.huey 其中run_huey.py(项目根目录中的一个文件)包含:
from app.tasking.tasks import my_huey as huey
if __name__ == '__main__':
pass
我懂了:
[2018-08-22 14:10:58,587] INFO:huey.consumer:MainThread:The following commands are available:
+ queue_task_create_cl_listing
+ queue_task_some_long_calculation
+ queue_task_dummy_create_task
显示任务可用。但是,如果我无法将已转换为任务的函数导入 app.main.views 文件,以便我可以通过视图函数调用它。例如,如果我添加:
from app.tasking.tasks import some_long_calculation_task
到 main.views 文件:
[91mError importing run_huey.huey?[0m
Traceback (most recent call last):
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 18, in load_huey
return load_class(path)
File "...\lib\site-packages\huey\utils.py", line 46, in load_class
__import__(path)
ModuleNotFoundError: No module named 'run_huey'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "...\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "...\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "...\Scripts\huey_consumer.exe\__main__.py", line 9, in <module>
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 43, in consumer_main
huey_instance = load_huey(args[0])
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 23, in load_huey
return load_huey(path)
File "...\lib\site-packages\huey\bin\huey_consumer.py", line 18, in load_huey
return load_class(path)
File "...\lib\site-packages\huey\utils.py", line 46, in load_class
__import__(path)
File "...\run_huey.py", line 12, in <module>
from app.tasking.tasks import my_huey as huey
File "...\app\tasking\tasks.py", line 3, in <module>
from app.main.cl import dummy_create_cl_listing, create_cl_listing
File "...\app\main\__init__.py", line 1, in <module>
from app.main import errors # noqa
File "...\app\main\errors.py", line 3, in <module>
from app.main.views import main
File "...\app\main\views.py", line 14, in <module>
from app.tasking.tasks import some_long_calculation_task
ImportError: cannot import name 'some_long_calculation_task'
我怎样才能解决这个问题?