Nerotix
Nerotix

Reputation: 375

Threading gives typeError

Im busy with a project for my study and I keep getting this error:

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

The function that produces this error is:

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))

I'm pretty sure it comes from the thread, as that is inside the error. But I can't figure out what is going wrong, it seems just fine to me. At the first few moments it doesn't give me an error but after 20 seconds or so, the error keeps popping up, even tho the script keeps running while these errors are printed out.

Upvotes: 1

Views: 6416

Answers (1)

DeepSpace
DeepSpace

Reputation: 81684

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

You are calling the r_serv.hset function and then assigning its return value to the target kwarg (which is then being called and raising the exception), instead of assigning the function itself to the target kwarg.

What you should be doing is:

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

Upvotes: 2

Related Questions