gpt4 book ai didi

python - 线程给出类型错误

转载 作者:行者123 更新时间:2023-12-01 03:52:07 26 4
gpt4 key购买 nike

我正忙于一个学习项目,但我不断收到此错误:

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 秒后,错误不断弹出,即使在打印出这些错误时脚本仍在运行。

最佳答案

t = threading.Thread(target=r_serv.hset("_id" + str(teller),
"vt", VTHandler(r_serv.hget("_id" + str(teller), "source"))))

您正在调用r_serv.hset函数,然后将其返回值分配给target kwarg(然后调用该kwarg并引发异常),而不是分配函数本身到 target kwarg。

你应该做的是:

t = threading.Thread(target=r_serv.hset, args=("_id" + str(teller),
"vt", VTHandler(r_serv.hget("_id" + str(teller), "source"))))

关于python - 线程给出类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38056227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com