在Python中执行绪时出现AssertionError [英] AssertionError when threading in Python

查看:2112
本文介绍了在Python中执行绪时出现AssertionError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令在Python中运行一些简单的线程:

I'm trying to run some simple threading in Python using:

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

other code runs in here

t1.join()

不幸的是我遇到了错误:

Unforunately I'm getting the error:

"AssertionError:组参数现在必须为空"

"AssertionError: group argument must be none for now"

我以前从未在Python中实现线程化,所以我不确定到底出了什么问题.有谁知道这是什么问题吗?

I've never implemented threading in Python before, so I'm a bit unsure as to what's going wrong. 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.

我也有一个后续查询. Analysis返回了一个字典,我该如何分配该字典以供原始方法使用?

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?

谢谢

推荐答案

您想改为指定target关键字参数:

You want to specify the target keyword parameter instead:

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

您可能打算将analysis作为运行目标,但将'samplequery自变量启动时:

You probably meant to make analysis the run target, but 'samplequery the argument when started:

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

Thread()的第一个参数是group参数,并且当前仅接受None作为参数.

The first parameter to Thread() is the group argument, and it currently only accepts None as the argument.

来自 threading.Thread()文档:

应始终使用关键字参数调用此构造函数.参数为:

This constructor should always be called with keyword arguments. Arguments are:

  • group 应该为None;当实现ThreadGroup类时保留给以后的扩展.
  • target run()方法要调用的可调用对象.默认为None,表示什么都不会被调用.
  • group should be None; reserved for future extension when a ThreadGroup class is implemented.
  • target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

这篇关于在Python中执行绪时出现AssertionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆