我正在实现一个多线程概念,它将划分一个批量 <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/