timer

Tim Golden mail at timgolden.me.uk
Tue Jun 30 09:09:43 EDT 2009


superpollo wrote:
> so why this does not work?
> 
>       1 #!/usr/bin/python
>       2
>       3 import threading
>       4
>       5 e = threading.Event()
>       6 t = threading.Timer(3.0, e.set())
>       7 t.start()
>       8 while not e.isSet():
>       9     print "stuff ",
> 
> it does *NOT* print (but it should, shouldn't it?), then exits after 3 
> sec but with error:

Nice try, but you're passing *the result of calling e.set*
as the function parameter to Timer. And the result of calling
e.set () is None. So you're passing None as the function-to-call.
Which it does. And then...

> TypeError: 'NoneType' object is not callable

Try passing the function instead:

threading.Timer (3.0, e.set).start ()

TJG



More information about the Python-list mailing list