我正忙着为我的学习项目而且我一直收到这个错误:
Exception in thread Thread-62:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: 'long' object is not callable
产生此错误的函数是:
teller = 0
def toRedis(dstip, srcip, dnsname):
global teller
ignoreDom = config.getSetting('setup', 'ignore')
if dnsname in ignoreDom:
pass
else:
teller += 1
answer = {"_id": teller, "destination": dstip, "source": srcip, "name": dnsname}
r_serv.hmset("_id" + str(teller), answer)
t = threading.Thread(target=r_serv.hset("_id" + str(teller),
"vt", VTHandler(r_serv.hget("_id" + str(teller), "source"))))
t.daemon = True
t.start()
print r_serv.hgetall("_id" + str(teller))
我很确定它来自线程,因为它在错误中。但我无法弄清楚出了什么问题,对我来说似乎没问题。在最初的几分钟它没有给我一个错误,但是在20秒左右之后,错误会一直弹出,即使脚本在打印出这些错误时仍在运行。
答案 0 :(得分:2)
t = threading.Thread(target=r_serv.hset("_id" + str(teller),
"vt", VTHandler(r_serv.hget("_id" + str(teller), "source"))))
您正在调用r_serv.hset
函数,然后将其返回值分配给target
kwarg(然后被调用并引发异常),而不是将函数本身分配给{{1 kwarg。
你应该做的是:
target