I am trying to use a Timer inside a method, as a way to wait some time, without blocking the script, as time.sleep would.
Outside of the class, the Timer code runs fine, but inside a class method, it returns the error: TypeError: 'NoneType' object is not callable
import time
from threading import Timer
openDuration = 10
### Valve class
class Valve():
def open(self, openDuration):
t = Timer(openDuration, Valve().dummyWait())
t.start()
t.join()
print("Valve open")
def dummyWait(self): # empty. Just used to wait some time
pass
Valve().open(openDuration)
While the code does run and prints "Valve open" after 10s, it returns this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\threading.py", line 1166, in run
self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable
What is causing this error message? It is my understanding, that I am using two variables, openduration & t, both of which get defined, therefore I don't understand the NoneType Error message here.