我本来希望将threading.Timer子类化,但是即使在最琐碎的情况下也会出现错误。
class MyDelayedEvent(threading.Timer):
def __init__(self, *args, **kwargs):
super(MyDelayedEvent, self).__init__(*args, **kwargs)
哪个给出错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
很奇怪,但有一点戳,我看到对象实际上是threading._Timer
,在python 2.7源中,Timer的定义如下
def Timer(*args, **kwargs):
return _Timer(*args, **kwargs)
class _Timer(Thread):
"""Call a function after a specified number of seconds:
...
( https://svn.python.org/projects/python/tags/r27a1/Lib/threading.py )
为什么python 2.7会费心创建一个只返回构造对象的函数? _Timer在这里有什么意义? _Timer的子类安全吗?