擅长:python、mysql、java
<p><code>Timer</code>接受一个参数数组和一个关键字参数dict,因此需要传递一个数组:</p>
<pre><code>import threading
def hello(arg):
print arg
t = threading.Timer(2, hello, ["bb"])
t.start()
while 1:
pass
</code></pre>
<p>你看到“b”是因为你没有给它一个数组,所以它把<code>"bb"</code>看作一个iterable;本质上就像你给它<code>["b", "b"]</code>。</p>
<p><code>kwargs</code>用于关键字参数,例如:</p>
<pre><code>t = threading.Timer(2, hello, ["bb"], {arg: 1})
</code></pre>
<p>有关关键字参数的信息,请参见<a href="http://docs.python.org/release/1.5.1p1/tut/keywordArgs.html" rel="noreferrer">http://docs.python.org/release/1.5.1p1/tut/keywordArgs.html</a>。</p>