TypeError: dict对象不可调用(在线程函数中)



我在使用线程同时执行功能的程序中出现错误,此过程是每小时运行一次的作业,输入的数据来自sql中的视图。

targetarg中调用的函数返回一个字典并表示字典对象是不可调用的。在函数内部,返回一个字典。我的疑问是这个函数应该返回什么,如果我不返回任何东西,它会影响任何其他线程吗?

# inside the jobs in django I call this function
def ticket_booking():  

query = " SELECT * FROM vw_ticket_list;"  
ttd = []
try:
result = query_to_dicts(query)
tickets = json.loads(to_json(result))
if tickets:
# Calling the vaccination push message (php).
for ticket in tickets:

# Getting Generic details used by all categories
full_name = tickets['full_name'] 
gender = tickets['gender']  
email =tickets[email]
if tickets['language_id'] == 1:  # book english movie tickets 

# Calling the function inside the Thread for a Syncronuz Call (Wait and Watch)
myThread = threading.Thread(target=book_english(email, full_name))
myThread.start()  
myThread.join()  
if tickets['language_id']  == 2:  # book italian movie tickets 
myThread = threading.Thread(target=book_italian( email, full_name, gender))
myThread.start()  # Starting the Thread
myThread.join() #Will return here if sth is returned

正如你在代码注释中看到的,如果book意大利语函数返回sth,只有这样它才能返回这里,我总共有5个线程要同时执行,book意大利语函数是这样的:

def book_italian(email,fullname,gender):
try
# posts data to another server #
b=requests.post(some postdata)
a =log.objects.create(log data from b in crct format)
return a--->{"Message":"Log created successfully"}

a是类型类字典,我试图将其更改为许多类型仍然给我同样的错误,这个作业在crontab中运行时没有运行。

当你使用threading.Thread执行某事时,你应该将target可调用对象(如函数)和相应的arguments(参数)分开,然后分别传递它们:

myThread = threading.Thread(target=book_italian, args=(email, full_name, gender))

参考文献

相关内容

  • 没有找到相关文章

最新更新