python - 当我在 python 中将 <class 'pandas.core.frame.DataFrame' > 作为参数发送时,为什么我在方法中收到多个值

标签 python python-3.x pandas python-multithreading

我正在实现一个多线程概念,它将划分一个批量 <class 'pandas.core.frame.DataFrame'>分成几块。当我将它作为参数发送到目标函数时,我收到了这样的错误
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]))

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

最佳答案

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

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

看看它是否有效...

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

关于python - 当我在 python 中将 <class 'pandas.core.frame.DataFrame' > 作为参数发送时,为什么我在方法中收到多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59465969/

相关文章:

python - 判断两行中第一行是否为标题

javascript - python : how to get hidden html contents from a HTML page

python - Pandas:从函数连续写入 csv

python - 如何获得第 3 方 cookie?

Python 机器人错误消息

python - 相对导入和目录结构(万亿次)

python - Pandas -Python : How do you write new lines in Pandas?

python - 如何过滤一列包含相似模式但另一列包含不同值的行

python - pyspark 将两个 rdd 合并在一起

python - 将 .py 文件和图像转换为独立可执行文件