【问题标题】:Threading in Python : Python 'args' is an invalid keyword argument for this function, why?Python 中的线程:Python 'args' 是此函数的无效关键字参数,为什么?
【发布时间】:2011-12-07 07:11:08
【问题描述】:

我已经为 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

我应该如何解决这个错误?

【问题讨论】:

    标签: python django django-models python-module python-multithreading


    【解决方案1】:

    我认为(编辑:I'm sure)您的模型名称为Thread。所以你尝试实例化Uzvy.models.Thread,而不是threading.Thread

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-04
      • 2019-06-23
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      相关资源
      最近更新 更多