Python Threading问题:TypeError in Threading. function takes 1 positional argument but 100 were given
在使用python多线程module Threading时:
import threading
t = threading.Thread(target=getTemperature, args = (id1))
t.start()
运行时报如上的错误,参考stackoverflow,如下解释:
The args kwarg of threading.Thread expects an iterable, and each element in that iterable is being passed to the target function.
Since you are providing a string for args:
t = threading.Thread(target=startSuggestworker, args = (start_keyword))
each character is being passed as a separate argument to startSuggestworker.
Instead, you should provide args a tuple:
t = threading.Thread(target=startSuggestworker, args = (start_keyword,))
也就是args传递的参数类型不对,即使一个参数也要时元组的形式给出
正确的传递方式如下:
import threading
t = threading.Thread(target=getTemperature, args = (id1,))
t.start()
Python Threading问题:TypeError in Threading. function takes 1 positional argument but 100 were given的更多相关文章
- 【Python】**kwargs和takes 1 positional argument but 2 were given
Python的函数定义中可以在参数里添加**kwargs——简单来说目的是允许添加不定参数名称的参数,并作为字典传递参数.但前提是——你必须提供参数名. 例如下述情况: class C(): def ...
- 问题TypeError: __init__() takes 1 positional argument but 2 were given解决方案
在搭建自动化框架时,遇到一个问题,如下图: 根据报错的意思,应该是__init__函数的问题, 位置应该是HomePage文件 立马去查看一下文件,如图: 原来是因为的粗心大意__init__(sel ...
- Python:XXX missing X required positional argument: 'self'
代码的一个小小Bug有时候会让人焦头烂额,费了很大劲搞明白的问题,如果不记录下来,是很容易遗忘的! 定义一个类,如果按照以下的方式使用,则会出现TypeError: testFunc() missin ...
- Python中的multiprocessing和threading
Python中的multiprocessing和threading分别使用来实现多进程编程和多线程编程的.其中threading比较简单,而前者比较繁琐. 下面,我们进行一下分析: 多线程--thre ...
- [python]多线程模块thread与threading
Python通过两个标准库(thread, threading)提供了对多线程的支持 thread模块 import time import thread def runner(arg): for i ...
- Python基础-TypeError:takes 2 positional arguments but 3 were given
Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...
- python学习笔记之使用threading模块实现多线程(转)
综述 Python这门解释性语言也有专门的线程模型,Python虚拟机使用GIL(Global Interpreter Lock,全局解释器锁)来互斥线程对共享资源的访问,但暂时无法利用多处理器的优势 ...
- python笔记9 线程进程 threading多线程模块 GIL锁 multiprocessing多进程模块 同步锁Lock 队列queue IO模型
线程与进程 进程 进程就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成.我们编写的程序用来描述进程要完成哪些功能以及如何完成:数据集则是程序在执行过程中所需要 ...
- python:TypeError: main() takes 0 positional arguments but 1 was given
TypeError: main() takes 0 positional arguments but 1 was given def main(self): 括号里加上self就好了
随机推荐
- SpringBoot2.0 项目中使用事务
参考博客: SpringBoot开启事务常见坑点 另外注意手动回滚事务需要 (1)在业务层方法上添加注解 @Transactional (2)在需要回滚的地方添加代码: TransactionAspe ...
- C#Npoi
https://download.csdn.net/download/youhmcq/7725559http://www.cnblogs.com/downmoon/archive/2012/04/11 ...
- python安装第三方库报错visual c++ 14.0 is required
使用python安装第三方库时报错如下: error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ ...
- 找不到servlet对应的class
javax.servlet.ServletException: Wrapper cannot find servlet class com.suntomor.lewan.pay.NotifyRecei ...
- python接口自动化(六)--发送get请求接口(详解)
简介 如果想用python做接口测试,我们首先有不得不了解和学习的模块.它就是第三方模块:Requests. 虽然Python内置的urllib模块,用于访问网络资源.但是,它用起来比较麻烦,而且,缺 ...
- 在linux(centos)系统安装redis教程
最近在切换服务器操作系统,简单记录一下 一.安装redis 1.检查是否有redis yum 源 yum install redis 2.下载fedora的epel仓库 yum install epe ...
- springboot~Profile开发环境与单元测试用不同的数据库
期望 希望开发环境dev用mysql 单元测试使用本机的h2数据库 引入依赖 compile('org.springframework.boot:spring-boot-starter-data-jp ...
- RDIFramework.NET V3.3 Web版新增报表管理功能模块-重量级实用功能
功能描述 在RDIFramework.NET V3.3 Web版本新增了全新的报表管理功能模块,非常实用的功能,重量级推荐.主要用于对日常常用的报表做定制展示.可以自动发布到模块(就可授权给指定资源访 ...
- SAMBA服务和FTP服务讲解(week3_day1)--技术流ken
samba服务 Smb主要作为网络通信协议; Smb是基于cs架构: 完成Linux与windows之间的共享:linux与linux之间共享用NFS 第一步:安装samba [root@ken ~] ...
- 1.Memcached 中文文档 - 概论(译官方文档)
原文地址:memcached手册 https://github.com/memcached/memcached/wiki/Overview 简介 Free & open source, ...