Python 中的线程:Python 'args'该函数的关键字参数无效,为什么?
我已经用 Python 编写了线程代码。
它抛出下面的错误。
我应该如何修复该错误?
from django.core.management import setup_environ
import settings
setup_environ(settings)
from threading import Thread
import urllib2
from django.db import transaction
from Uzvy.models import *
feed_obj_list = Uzvy.objects.all().order_by('uzvy_id')
print len(feed_obj_list)
def save_thread_list(feed_list):
print len(feed_list)
number_of_threads = 4
count=0
total=len(feed_obj_list)
step=total/number_of_threads
print len(feed_obj_list[0:100])
if total>0:
while (count*step)<=total:
if count==0:
t=Thread(target=save_thread_list,args=(feed_obj_list[0:step],))
t.start()
else:
t=Thread(target=save_thread_list,args=(feed_obj_list[count*step:(count+1)*step],))
t.start()
count=count+1
如果我运行此代码,我会收到以下错误。
我在这里犯了任何错误,我需要包含任何文件
Traceback (most recent call last):
File "threading_by_venkat_2.py", line 67, in <module>
t=Thread(target=save_thread_list,args=(feed_obj_list,))
File "/usr/lib/python2.6/dist-packages/django/db/models/base.py", line 243, in __init__
raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]
TypeError: 'args' is an invalid keyword argument for this function
我应该如何修复此错误?
I have written code for threading in Python.
It throws the error below.
How should I fix that error?
from django.core.management import setup_environ
import settings
setup_environ(settings)
from threading import Thread
import urllib2
from django.db import transaction
from Uzvy.models import *
feed_obj_list = Uzvy.objects.all().order_by('uzvy_id')
print len(feed_obj_list)
def save_thread_list(feed_list):
print len(feed_list)
number_of_threads = 4
count=0
total=len(feed_obj_list)
step=total/number_of_threads
print len(feed_obj_list[0:100])
if total>0:
while (count*step)<=total:
if count==0:
t=Thread(target=save_thread_list,args=(feed_obj_list[0:step],))
t.start()
else:
t=Thread(target=save_thread_list,args=(feed_obj_list[count*step:(count+1)*step],))
t.start()
count=count+1
If I run this code, I am getting the following error.
I did any mistake here are i need include any files
Traceback (most recent call last):
File "threading_by_venkat_2.py", line 67, in <module>
t=Thread(target=save_thread_list,args=(feed_obj_list,))
File "/usr/lib/python2.6/dist-packages/django/db/models/base.py", line 243, in __init__
raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]
TypeError: 'args' is an invalid keyword argument for this function
How should I fix this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为(编辑:我确定)你有名为
Thread
的模型。因此,您尝试实例化Uzvy.models.Thread
,而不是threading.Thread
I think (edited: I'm sure) you have model with name
Thread
. So you try to instantiateUzvy.models.Thread
, notthreading.Thread