1

When connecting to a gearman daemon, if the daemon url or port are incorrect and no connection can be made an exception is raised:

      File "/usr/lib/python2.7/dist-packages/gearman/client.py", line 205, in establish_request_connection
    raise ServerUnavailable('Found no valid connections: %r' % self.connection_list)

gearman.errors.ServerUnavailable: Found no valid connections: [<GearmanConnection localhost:4700 connected=False>]

I want to catch the exception and handle it gracefully but the code below doesn't do that. The exception and traceback is displayed as though I haven't tried to catch the exception.

The code that generates and tries to trap the exception is:

import gearman
from gearman.errors import ConnectionError, InvalidAdminClientState, ServerUnavailable
try:
    gmClient = gearman.GearmanClient(['localhost:4730'])
except gearman.errors.ServerUnavailable, e:
# I've also tried except ServerUnavailable, e: - same result.
    print(e)

How do I correctly catch gearman client connection exceptions?

RoyHB
  • 1,715
  • 1
  • 22
  • 38

1 Answers1

0

The ServerUnavailable exception is raised when you try to submit a job. Try this:

import gearman

gmClient = gearman.GearmanClient(['localhost:4700'])

try:
    request = gmClient.submit_job('reverse', 'Hello World!')
except gearman.errors.ServerUnavailable, e:
    print("caught ServerUnavailable")
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • I am getting the same error for some tasks. Why do I get this error? Is it due to load? I use supervisord to run 4 workers. – Hussain Nov 06 '14 at 05:52