AttributeError in __dell__ #36

Closed
speedplane opened this Issue Mar 4, 2014 · 1 comment

Projects

None yet

2 participants

@speedplane

I am seeing AttributeError exceptions being raised in my logs and I believe the culprit is amqp/transport._AbstractTransport.__del__.

As stated in this SO post (http://stackoverflow.com/questions/18058730/python-attributeerror-on-del), the __del__ function may have been called after modules have started to be unloaded and set to None. In the __del__ function for _AbstractTransport, you have to check the socket module before grabbing a property from it. Below is a proposed fix to the __del__ method:

  def __del__(self):
        try:
            self.close()
        except e:
            if socket and isinstance(e, socket.error):
               pass
            else:
               raise
        finally:
            self.sock = None

Similarly, you need to check socket in the close method. Here is a proposed fix:

  def close(self):
        if socket and self.sock is not None:
            self._shutdown_transport()
            # Call shutdown first to make sure that pending messages
            # reach the AMQP broker if the program exits after
            # calling this method.
            self.sock.shutdown(socket.SHUT_RDWR)
            self.sock.close()
            self.sock = None
        self.connected = False
@ask
Member
ask commented Mar 5, 2014

Thanks! Indeed, this usually happens if you have threads and a thread wakes up after the gc collected the socket module.

@ask ask closed this in 78f9b9b Mar 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment