gpt4 book ai didi

python - gearman - 不断出现类型错误

转载 作者:行者123 更新时间:2023-11-28 16:45:30 26 4
gpt4 key购买 nike

我有一个简单的 python 脚本来发送 gearman 任务:

客户:

        # "source" is a simple tuple
client = GearmanClient(['localhost'])
client.submit_job('queue_feed', simplejson.dumps(source))

服务器:

def queue_feed(work, job):
source = simplejson.loads(job.data)
print source

if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == "spawn":
worker = GearmanWorker(['localhost'])
#nohup python /home/padsquad/apps/gearman_articles.py spawn &
worker.register_task('queue_feed', queue_feed)
print 'working...'
worker.work()

我不确定我在这里做错了什么,gearman 服务器一直给我以下错误:

TypeError: Expecting byte string, got <type 'NoneType'>

最佳答案

我最好的猜测是函数 queue_feed 应该返回一些东西:例如:

def queue_feed(work, job):
source = simplejson.loads(job.data)
print source
return source

如果您没有明确地从 python 函数返回某些内容,它会隐式返回 None 这就是 python 提示获取 NoneType

的原因

关于python - gearman - 不断出现类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14260545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com