I'm using twisted with GTK, and the following code runs when a connection could not be established:
def connectionFailed(self, reason):
#show a "connect failed" dialog
dlg = gtk.MessageDialog(
type=gtk.MESSAGE_ERROR,
buttons=gtk.BUTTONS_CLOSE,
message_format="Could not connect to server:\n%s" % (
reason.getErrorMessage()))
responseDF = defer.Deferred()
dlg.set_title("Connection Error")
def response(dialog, rid):
dlg.hide_all()
responseDF.callback(rid)
dlg.connect("response", response)
dlg.show_all()
self.shutdownDeferreds.append(responseDF)
self.shutdownDeferreds
is a list of deferreds that is set up so that the reactor does not stop until they are all called.
Now, I happened to press CTRL+C
at the same time as the connection failed. The dialog did pop up, but when I press Close
, I get:
Traceback (most recent call last):
File "C:\Users\DrClaud\bumhunter\gui\controller.py", line 82, in response
dlg.hide_all()
NameError: free variable 'dlg' referenced before assignment in enclosing scope
Traceback (most recent call last):
File "C:\Users\DrClaud\bumhunter\gui\controller.py", line 82, in response
dlg.hide_all()
NameError: free variable 'dlg' referenced before assignment in enclosing scope
Any ideas why that might happen?