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?
The
ServerUnavailable
exception is raised when you try to submit a job. Try this: