Python gearman基本示例错误

时间:2015-07-05 03:39:20

标签: python gearman python-gearman

我正在尝试使用Python gearman模块进行字符串反转的基本示例 已在端口4730上使用IIS设置了我的localhost 但是我收到了错误

raise UnknownCommandError(missing_callback_msg)
UnknownCommandError: Could not handle command: 'GEARMAN_COMMAND_TEXT_COMMAND' - {'raw_text': 'HTTP/1.1 400 Bad Request\r'}

Client.py

    import gearman
    #  setup client, connect to Gearman HQ
    gm_client = gearman.GearmanClient(['localhost:4730'])
    print 'Sending job...'
    request = gm_client.submit_job('reverse', 'Hello World!')
    print "Result: " + request.result

Worker.py

    import gearman
    gm_worker = gearman.GearmanWorker(['localhost:4730'])
    #  define method to handled 'reverse' work
    def task_listener_reverse(gearman_worker, gearman_job):
            print 'reporting status'
            return reversed(gearman_job.data)
    gm_worker.set_client_id('your_worker_client_id_name')
    gm_worker.register_task('reverse', task_listener_reverse)
    gm_worker.work()

有关为何可能发生这种情况以及如何解决相同问题的任何建议

2 个答案:

答案 0 :(得分:1)

而不是return reversed(gearman_job.data)尝试使用return ''.join([i for i in reversed(gearman_job.data[::1])])

返回reversed(...)将为您提供Type Error

答案 1 :(得分:1)

当前版本的gearman具有不同的导入结构。您需要说from gearman.worker import GearmanWorkerfrom gearman.client import GearmanClient

此外,返回应该说return ''.join([i for i in reversed(gearman_job.data[::1])])以获得反向字符串。