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

发布于 2024-12-20 02:19:05 字数 1509 浏览 2 评论 0原文

我已经用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-12-27 02:19:05

我认为(编辑:我确定)你有名为 Thread 的模型。因此,您尝试实例化 Uzvy.models.Thread,而不是 threading.Thread

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文