I am trying to run a basic example of gearman using python-gearman library available here. I am running python 2.7.3
Worker:
import gearman
gm_worker = gearman.GearmanWorker(['localhost:4730'])
def task_listener_reverse(gearman_worker, gearman_job):
print 'reporting status'
return reversed(gearman_job.data)
gm_worker.set_client_id('testclient')
gm_worker.register_task('reverse', task_listener_reverse)
gm_worker.work()
Client:
import gearman
gm_client = gearman.GearmanClient(['localhost:4730'])
print 'Sending job...'
request = gm_client.submit_job('reverse', 'Hello World!')
print "Result: " + request.result
I am getting the following error (full trace available here)
File "/Users/developer/gearman/connection_manager.py", line 27, in _enforce_byte_string
raise TypeError("Expecting byte string, got %r" % type(given_object))
TypeError: Expecting byte string, got <type 'reversed'>
Any help would be appreciated!
Thanks.
reversed()
returns an iterator, not a bytestring. Use the negative stride slicing trick instead:This returns a reversed string instead.
Compare: