earl / beanstalkc

A simple beanstalkd client library for Python
Apache License 2.0
458 stars 115 forks source link

Handle beanstalkd shutdown/restart #3

Closed silas closed 14 years ago

silas commented 14 years ago
  1. Start beanstalkd
  2. Create the following script and run

    http://gist.github.com/239124

  3. Kill the beanstalkd server

Result:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    job = beanstalk.reserve()
  File "/usr/lib/python2.6/site-packages/beanstalkc.py", line 109, in reserve
    ['DEADLINE_SOON', 'TIMED_OUT'])
  File "/usr/lib/python2.6/site-packages/beanstalkc.py", line 76, in interact_job
    jid, size = self.interact(command, expected_ok, expected_err)
  File "/usr/lib/python2.6/site-packages/beanstalkc.py", line 55, in interact
    status, results = self.read_response()
  File "/usr/lib/python2.6/site-packages/beanstalkc.py", line 65, in read_response
    return response[0], response[1:]
IndexError: list index out of range

Additional Information:

If I put a print above line 65 I can see that its getting an empty list and failing (obviously because response[1:] doesn't exist).

Not sure how you want to handle this, but raising an exception when the connection is lost is probably a good start.

rtyler commented 14 years ago

I think by commenting I'll be CC'ed on future updates to this ticket.

earl commented 14 years ago

Thanks. I just pushed three commits to master that fix this and also unify the handling of socket exceptions.

earl commented 14 years ago

The gist of it: all exceptional socket cases should be wrapped in beanstalkc.SocketError.

rtyler commented 14 years ago

Instead of defining a new exception class instead of using IOError or socket.error, if beanstalkc raises a standard connection error, then there's no need to update worker code of mine to additionally catch beanstalkc.SocketError

silas commented 14 years ago

Thanks earl