【发布时间】:2020-07-25 21:45:36
【问题描述】:
import _thread
class cl:
def func_one(self, conn):
...
def func_two(self):
str_key = "ABC"
_thread.start_new_thread(self.func_one, (self,str_key))
一旦解释,它就会返回以下内容:
TypeError: func_one() takes 2 positional arguments but 3 were given
我尝试过不带 self 的线程 func_one()。一开始是 (self.func_one()) 但后来它返回
NameError: name 'func_one' is not defined
如果我想从 func_two() 线程化 func_one() 应该怎么做?它们属于同一个类 cl()。
我使用以下方法调用 func_two():
if(__name__ == "__main__"):
c = cl()
c.func_two()
更新:
我找到了解决问题的方法:
import _thread
class cl:
def func_one(self, conn, tmp):
...
def func_two(self):
str_key = "ABC"
_thread.start_new_thread(self.func_one, (str_key,None))
【问题讨论】:
标签: python python-3.x typeerror python-multithreading nameerror