I am using xmpppy libary to write a XMPP IM robot.
I want to act on disconnects, but I don't know how to detect disconnects. This could happen if your Jabber server crashes or if you have lost your internet connection.
I found the callback, RegisterDisconnectHandler(self, DisconnectHandler), but it didn't work for the network failure, it only works when I explicitly call the method "disconnect". 
How do I detect a network failure or server crash?
Did you try waiting 30 minutes after the network failure?  Depending on your network stack's settings, it could take this long to detect.  However, if you're not periodically sending on the socket, you may never detect the outage.  This is why many XMPP stacks periodically send a single space character, using an algorithm like:

Set timer to N seconds
On sending a stanza, reset the timer to N
When the timer fires, send a space.
A script im robot with xmpppy of python, how to detect network failure?