作为python中的args,python,python-3.x,pandas,python-multithreading"/>

首页 > 解决方案 > 为什么我在发送时会在方法中收到多个值作为python中的args

问题描述

我正在实现一个多线程概念,它将一个大块<class 'pandas.core.frame.DataFrame'>分成一些块。当我将它作为 args 发送到目标函数时,我收到了如下错误

TypeError: thread_chunking() takes 2 positional arguments but 3 were given.

我尝试在目标方法中接收为 *args ,但它作为元组给出,而没有内容仅在其中标题。

我的代码如下,

thread_chunk=pandas.read_sql("some sql here")
....
thread_name= threading.Thread(target=self.thread_chunking,args=thread_chunk[0:100]))

那么如何在python中的线程中将a传递给目标函数

标签: pythonpython-3.xpandaspython-multithreading

解决方案


args是目标调用的参数元组。尝试将其传递为:

thread_name= threading.Thread(target=self.thread_chunking,args=(thread_chunk[0:100],))

看看有没有效果...

链接到文档:https ://docs.python.org/2/library/threading.html#thread-objects


推荐阅读