当我执行这段代码
import class3,thread
t3 = class3.test3
thread.start_new_thread(t3.func3,())
其中class3
为
class test3(object):
def func3():
while 1:
print "working!!"
我得到一个错误:
由
启动的线程出现未处理异常
这个错误的含义是什么,我如何修复它?
调用它,看看会发生什么:
TypeError: unbound method func3() must be called with test3 instance as first argument (got nothing instead)
你必须让func3
成为一个实例方法并初始化你的类:
class test3(object):
def func3(self):
while True:
print "working!!"
t3 = test3()
或使func3
变为staticmethod
:
class test3(object):
@staticmethod
def func3():
while True:
print "working!!"