I want to disconnect cleanly, and then stop the reactor. If I do this, however:
controller.connection.disconnect()
reactor.stop()
then I get a "connection was lost in a non-clean fashion" message. If I insert a time.sleep(1)
in between them, the connection closes cleanly. How can I wait until the connection is really closed?
You could listen for a callback from twisted which indicates that the connection has been disconnected. This blog describes an approach to do this.