Created
September 21, 2011 22:38
-
-
Save harleyholt/1233525 to your computer and use it in GitHub Desktop.
Example Python Gearman Worker (for python Gearman 2.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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