我知道它很混乱,但线程是如此混乱…我不知道问题是在我的辛塔克斯还是在我使用的方法。。。 def do inserts in mysql(它在非线程化的情况下工作),另一个奇怪的事情是,在运行代码之后,我注意到行被正确插入,但我仍然得到“self.\u target(*self.*args,**self.\u kwargs)” TypeError:“int”对象不可调用
def thistaginsert(tagy):
global idn
global forbidentags
global termcount
tagy = tagy[0]
if not tagy.isdigit():
if not tagy in forbidentags:
wordpress.execute(s_term % tagy)
term0 = wordpress.fetchall()
term0 = term0[0][0]
if term0 == 0:
tmp_i_term = i_term.format(tag1=tagy, tag2=tagy)
wordpress.execute(tmp_i_term)
cnx2.commit()
tmp_s_termname = s_termname.format(buceta=tagy)
wordpress.execute(tmp_s_termname)
term = wordpress.fetchall()
term = term[0]
wordpress.execute(i_termtax % term)
cnx2.commit()
wordpress.execute(s_tax % term)
tax_id = wordpress.fetchall()
tax_id = tax_id[0][0]
tmp_i_RL = i_RL.format(idn=idn, taxid=tax_id)
wordpress.execute(tmp_i_RL)
cnx2.commit()
termcount += 1
else:
tmp_s_termname = s_termname.format(buceta=tagy)
wordpress.execute(tmp_s_termname)
term = wordpress.fetchall()
term = term[0]
wordpress.execute(s_tax % term)
tax_id = wordpress.fetchall()
tax_id = tax_id[0][0]
tmp_i_RL = i_RL.format(idn=idn, taxid=tax_id)
wordpress.execute(tmp_i_RL)
cnx2.commit()
termcount += 1
return termcount
.
.
. #many lines later
if tags:
for tag in tags:
ttt = Thread(target=thistaginsert(tag))
ttt.start()
threads.append(ttt)
else:
print('no tags')
您直接调用函数,然后将结果作为目标函数传递给
Thread()
构造函数。因为函数返回一个int,这就解释了错误;您试图使用int作为线程的入口点,而int是不可调用的。在假设您打算在另一个线程上调用函数。要做到这一点,请更改以下内容:
收件人:
^{pr2}$正如评论中指出的,您也可以这样做:
^{3}$相关问题 更多 >
编程相关推荐