Python中的线程:Python'args'是这个函数的无效关键字参数,为什么?

时间:2021-03-07 20:40:43

I have written code for threading in Python.

我已经在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?

我该如何解决这个错误?

1 个解决方案

#1


1  

I think (edited: I'm sure) you have model with name Thread. So you try to instantiate Uzvy.models.Thread, not threading.Thread

我认为(编辑:我确定)你的模型名为Thread。所以你试图实例化Uzvy.models.Thread,而不是threading.Thread

#1


1  

I think (edited: I'm sure) you have model with name Thread. So you try to instantiate Uzvy.models.Thread, not threading.Thread

我认为(编辑:我确定)你的模型名为Thread。所以你试图实例化Uzvy.models.Thread,而不是threading.Thread