在windows上使用huey会有坑如下。
redis,phthon环境已经安装好。
安装好huey后,使用如下实例:
1.demo.py 任务worker文件,简单的加法
from config import huey
@huey.task()
def add(a, b):
return a + b
2.直接运行worker
python huey_consumer.py -w 1 -k process demo.huey
使用process模型就会报错
C:\Users\prokher\Desktop\HueyTest>huey_consumer.py -w 1 -k process main.huey
[2017-03-11 00:30:20,280] INFO:huey.consumer:2688:Huey consumer started with 1 process, PID 2688
[2017-03-11 00:30:20,280] INFO:huey.consumer:2688:Scheduler runs every 1 seconds.
[2017-03-11 00:30:20,280] INFO:huey.consumer:2688:Periodic tasks are enabled.
[2017-03-11 00:30:20,295] INFO:huey.consumer:2688:The following commands are available:
+ count_beans
Traceback (most recent call last):
File "C:\Program Files\Python36\Scripts\huey_consumer.py", line 49, in <module>
consumer_main()
File "C:\Program Files\Python36\Scripts\huey_consumer.py", line 45, in consumer_main
consumer.run()
File "c:\program files\python36\lib\site-packages\huey\consumer.py", line 439, in run
self.start()
File "c:\program files\python36\lib\site-packages\huey\consumer.py", line 430, in start
self.scheduler.start()
File "c:\program files\python36\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "c:\program files\python36\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "c:\program files\python36\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "c:\program files\python36\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "c:\program files\python36\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Consumer._create_process.<locals>._run'
C:\Users\prokher\Desktop\HueyTest>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files\python36\lib\multiprocessing\spawn.py", line 99, in spawn_main
new_handle = reduction.steal_handle(parent_pid, pipe_handle)
File "c:\program files\python36\lib\multiprocessing\reduction.py", line 82, in steal_handle
_winapi.PROCESS_DUP_HANDLE, False, source_pid)
OSError: [WinError 87] The parameter is incorrect
3. git上已经有报告
https://github.com/coleifer/huey/issues/208
4.如果使用thread方式则没有问题
python huey_consumer.py -w 2 -k thread demo.huey