anonymous function?

flupke flupke at nonexistingdomain.com
Wed Aug 18 07:40:58 EDT 2004


Hi,

i'm not sure what the exact type of function is called
for what i'm trying to do but here goes:

------ code -----
def OnClick(self, event):
     ...
     elif ( id == ID_BUTTON_CHECK ):
         if __debug__: print " Check pushed"
         minutes = self.check_time.GetValue()
         t = None
         if ( self.check.GetLabel() == "check" ):
             if ( minutes != "" ):
                 self.handleCommand("Check %s minutes\n" % str(minutes))
                 def sendCheckCommand():
                     self.connection.message("CHECK")
                 t = threading.Timer(10.0, sendCheckCommand() )
                 t.start() printed
                 self.updateGUI("CHECK_WITH_TIME")
------ code -----

The relevant code being the sendCheckCommand() function declared in the
OnClick function. This code starts a timer that should execute
self.connection.message("CHECK") every 30 seconds. I think this is an
anonymous (in Java it is) function and is really not meant to be a
"real" class function. But when i execute the code, it works 1 time but 
the second time it doesn't work anymore and i get this error:

Exception in thread Thread-2:
Traceback (most recent call last):
   File "C:\Python23\lib\threading.py", line 436, in __bootstrap
     self.run()
   File "C:\Python23\lib\threading.py", line 544, in run
     self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable

How can i accomplish this?

Thanks
Benedict



More information about the Python-list mailing list