sourcecode

Saturday, April 13, 2013

Python with Gearman (as client)

My planned structure: C++ as the worker in the backend, Python as the client at the front end, and Gearman is the agent in between.

Now test the front end.

1. Start up gearmand server and and sample worker. (word counter, from last post)

2. Install python-gearman module:
http://www.geeksww.com/tutorials/web_development/python/installation/how_to_install_python_gearman_client_module.php

3. Write a test python file:
http://www.saltycrane.com/blog/2010/04/notes-using-gearman-with-python/
http://pythonhosted.org/gearman/client.html
#!/usr/bin/python
import gearman
def check_request_status(job_request):
    if job_request.complete:
        print ("Job finished! ")
    elif job_request.timed_out:
        print ("Job timed out!")
    elif job_request.state == JOB_UNKNOWN:
        print ("Job connection failed!" )

gm_client = gearman.GearmanClient(['localhost:4730', 'otherhost:4730'])

# See gearman/job.py to see attributes on the GearmanJobRequest
# Defaults to PRIORITY_NONE, background=False (synchronous task), wait_until_complete=True
completed_job_request = gm_client.submit_job("wwcc", "arbitrary binary data")
check_request_status(completed_job_request)

Here the #! version should be matching the default python used by gearman module. I typed #!/usr/bin/python3.3, which would not work.

No comments: