+ -
当前位置:首页 → 问答吧 → TypeError: 'int' object is not callable

TypeError: 'int' object is not callable

时间:2011-01-30

来源:互联网

  1. #coding: utf-8
  2. import threading

  3. class Test(threading.Thread):
  4.         def __init__(self, dfile, start, end):
  5.                 threading.Thread.__init__(self)
  6.                 self.dfile= dfile
  7.                 self.start = start
  8.                 self.end = end

  9.         def run(self):
  10.                 global mutex
  11.                 mutex.acquire()
  12.                 self.dfile.seek(self.start, 0)
  13.                 content = self.dfile.read(self.end-self.start+1)
  14.                 print 30*'+'
  15.                 print content
  16.                 print 30*'+'
  17.                 mutex.release()

  18. if __name__ =="__main__":
  19.         file = open("123.html", "r")
  20.         threads = []
  21.         mutex = threading.Lock()
  22.         for x in range(5):
  23.                 threads.append(Test(file, x*100, x*100+100))
  24.        
  25.         for t in threads:
  26.                 t.start()

  27.         for t in threads:
  28.                 t.join()
复制代码
多线程读文件出现TypeError: 'int' object is not callable的错误,纠结了半天了....

作者: butterinsect   发布时间: 2011-01-30

第8行 self.start = start
传入的 start 是 int
然后你就调用了t.start()

作者: STLT1   发布时间: 2011-01-30