Skip to content

Instantly share code, notes, and snippets.

@harleyholt
Created September 21, 2011 22:38
Show Gist options
  • Save harleyholt/1233525 to your computer and use it in GitHub Desktop.
Save harleyholt/1233525 to your computer and use it in GitHub Desktop.
Example Python Gearman Worker (for python Gearman 2.0)
from gearman import GearmanWorker
# The function that will do the work
def echoer(worker, job):
print job.data
return job.data
# Establish a connection with the job server on localhost--like the client,
# multiple job servers can be used.
worker = GearmanWorker(['127.0.0.1'])
# register_task will tell the job server that this worker handles the "echo"
# task
worker.register_task('echo', echoer)
# Once setup is complete, begin working by consuming any tasks available
# from the job server
print 'working...'
worker.work()
# The worker will continue to run (waiting for new work) until exited by
# code or an external signal is caught
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment