简体   繁体   English

在Python中进行线程化时的AssertionError

[英]AssertionError when threading in Python

I'm trying to run some simple threading in Python using: 我正在尝试使用Python运行一些简单的线程:

t1 = threading.Thread(analysis("samplequery"))
t1.start()

other code runs in here

t1.join()

Unforunately I'm getting the error: 不幸的是我收到了错误:

"AssertionError: group argument must be none for now" “AssertionError:group参数现在必须为none”

I've never implemented threading in Python before, so I'm a bit unsure as to what's going wrong. 我之前从未在Python中实现过线程,所以我有点不确定出了什么问题。 Does anyone have any idea what the problem is? 有谁知道问题是什么?

I'm not sure if it's relevant at all, but analysis is a method imported from another file. 我不确定它是否相关,但分析是从另一个文件导入的方法。

I had one follow up query as well. 我也有一个跟进查询。 Analysis returns a dictionary, how would I go about assigning that for use in the original method? Analysis返回一个字典,我将如何分配在原始方法中使用?

Thanks 谢谢

You want to specify the target keyword parameter instead: 您想要指定target关键字参数:

t1 = threading.Thread(target=analysis("samplequery"))

You probably meant to make analysis the run target, but 'samplequery the argument when started : 您可能打算对运行目标进行analysis ,但是'samplequery 在启动时 'samplequery参数:

t1 = threading.Thread(target=analysis, args=("samplequery",))

The first parameter to Thread() is the group argument, and it currently only accepts None as the argument. Thread()的第一个参数是group参数,它当前只接受None作为参数。

From the threading.Thread() documentation : threading.Thread()文档

This constructor should always be called with keyword arguments. 应始终使用关键字参数调用此构造函数。 Arguments are: 参数是:

  • group should be None ; 应为None ; reserved for future extension when a ThreadGroup class is implemented. 在实现ThreadGroup类时保留用于将来的扩展。
  • target is the callable object to be invoked by the run() method. targetrun()方法调用的可调用对象。 Defaults to None , meaning nothing is called. 默认为None ,表示不调用任何内容。

您需要提供target属性:

t1 = threading.Thread(target = analysis, args = ('samplequery',))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM