multithreading - 排除 “unhandled exception in thread”错误

标签 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!!"

我收到一个错误:

Unhandled exception in thread started by <unbound method test3.func3>



此错误的含义是什么,我该如何解决?

最佳答案

调用它,看看会发生什么:

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!!"

关于multithreading - 排除 “unhandled exception in thread”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15626435/

相关文章:

multithreading - 如何从启动终端/线程中分离repl?

c - Spin Loop 在缓存一致性方面的开销

java - 测试线程数组

c++ - 如何异步执行从 unique_ptr 到对象的方法?

python - 在后台调用Python函数

Python 选择和计数元素

python - 如何使用线程获取数据并将数据写入同一个文本文件

java - 并发LRU缓存实现

Python 2 绑定(bind) Net-SNMP 错误 - undefined symbol : netsnmp-memdup

python - 谁能给我解释一下 "guardian pattern"