Search code examples
pythonpython-3.xpandaspython-multithreading

Why am I receiving multiple values in the method when I'm sending a <class 'pandas.core.frame.DataFrame'> as args in python


I'm implementing a multi threading concept that will divide a bulk <class 'pandas.core.frame.DataFrame'> into some chunks. When I'm sending it as args to the target function I'm getting the error like

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

I tried with receiving as *args in the target method but it is giving as tuple without the content only heading inside of it.

My code is below,

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

So how can I pass a to a target function in threading in python


Solution

  • args is the argument tuple for the target invocation. Try to maybe pass this as:

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

    See if it works...

    Link to the docs: https://docs.python.org/2/library/threading.html#thread-objects