2013-03-25 69 views
2

當我執行這個代碼故障排除 「在線程未處理的異常」 錯誤

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>

是什麼意思這個錯誤,以及我如何解決它?

回答

0

調用它,看看會發生什麼:

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