Multithreading “故障排除”;线程中未处理的异常";错误
当我执行这个代码时Multithreading “故障排除”;线程中未处理的异常";错误,multithreading,python-2.7,Multithreading,Python 2.7,当我执行这个代码时 import class3,thread t3 = class3.test3 thread.start_new_thread(t3.func3,()) 其中class3为 class test3(object): def func3(): while 1: print "working!!" 我得到一个错误: 由启动的线程中存在未处理的异常 此错误的含义是什么?如何修复它?调用它,看看会发生什么: TypeError: u
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
astaticmethod
:
class test3(object):
@staticmethod
def func3():
while True:
print "working!!"