擅长:python、mysql、java
<p>在赋值<code>self.args = args</code>时,您将值作为一个元组来获取,因此您应该首先将其获取/解析为元组,然后将其传递给<code>add</code>函数。
所以你要做的就是把你的<code>args</code>做成一个元组。你知道吗</p>
<p>下面是已修改的代码,标记行已更改。你知道吗</p>
<pre><code>import threading
class MyThread(threading.Thread):
def __init__(self, target, *args):
self._des = target
self.args = tuple(args) // making it to tuple
threading.Thread.__init__(self,)
self._stopper = threading.Event()
def run(self):
self._des(*self.args)
def stop(self):
self._stopper.set()
def stopped(self):
return self._stopper.isSet()
def add(a,b):
print(a+b)
if __name__ == "__main__":
f1 = MyThread(add, 1, 2)
f1.start()
f1.join()
</code></pre>
<p>希望这有帮助。你知道吗</p>