Joe
Joe

Reputation: 1772

python - gearman - keep getting typeerror

I have a simple python script to send gearman tasks:

Client:

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

Server:

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()

I'm not sure what I'm doing wrong here, the gearman server keeps giving me the following error:

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

Upvotes: 2

Views: 643

Answers (1)

mgilson
mgilson

Reputation: 310089

My best guess is that the function queue_feed is supposed to return something: e.g.:

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

If you don't explicitly return something from a python function, it implicitly returns None which is why python is complaining about getting NoneType

Upvotes: 4

Related Questions