anonymous function?

Benjamin Niemann b.niemann at betternet.de
Wed Aug 18 14:18:43 CEST 2004


 > t = threading.Timer(10.0, sendCheckCommand() )
This will *execute* sendCheckCommand at this point (what you mean by 'it 
works 1 time'), implicitly return None, which is passed to the Timer 
constructor, which in turn raises the mentioned exception.
Omit the () to get a reference to the function.

 > I think this is an
 > anonymous (in Java it is) function and is really not meant to be a
 > "real" class function.
I would prefer:
    t = threading.Timer(10.0, lambda: self.connection.message("CHECK"))
or for compatibility with older python versions:
    t = threading.Timer(10.0, lambda s=self:
         s.connection.message("CHECK"))



More information about the Python-list mailing list