【发布时间】:2016-08-09 20:57:27
【问题描述】:
我打算并行运行多个作业,并使用作业队列遵循示例here,但是当我尝试传递参数时,它执行了一次并引发了异常'NoneType' object is not callable。代码如下:
import Queue
import schedule
import threading
import time
def job(arg):
print 'Argument is %s' % arg
def worker_main():
while True:
try:
job_func = jobqueue.get()
job_func()
except Exception as e:
print e
jobqueue = Queue.Queue()
schedule.every(2).seconds.do(jobqueue.put, job(1))
schedule.every(2).seconds.do(jobqueue.put, job(2))
worker_thread = threading.Thread(target=worker_main)
worker_thread.start()
while True:
try:
schedule.run_pending()
time.sleep(1)
except Exception as e:
print e
sys.exit()
输出是:
Arg is 1
Arg is 2
'NoneType' object is not callable
'NoneType' object is not callable
'NoneType' object is not callable
'NoneType' object is not callable
'NoneType' object is not callable
'NoneType' object is not callable
...
有解决这个问题的想法吗?
【问题讨论】:
标签: python python-2.7 queue scheduled-tasks scheduler