Python Threading, list of 10 links taken as 10 positional arguments
<p>got a spider that is trying to crawl and add to a database, and thought I would use threading to quicken things up a little bit </p>

<p>here is the code:</p>

<pre><code>def final_function(link_set):
    root = 'http://www.rightmove.co.uk'
    pages = []

    for link in link_set:


        try:
            links = forty_page_getter(link)
            pages.append(links)
        except:
            print('not possible for:' + str(link))
            pass
    flattened = [item for sublist in pages for item in sublist]
    print('flattened done')

    for page in flattened:
        print(len(flattened))
        try:
            page_stripper(link=(root+page))
        except:
            print('couldnt do it for')
            pass
</code></pre>

<p>so that is the final function that takes in a list of links as an argument.
 My problem is here:</p>

<pre><code>if __name__ == "__main__":

    areas = pd.read_csv('postcodes.csv')
    areas = areas['0']
    result_list = split_list(flattened=areas, chunk_size=10)
    threads = []
    outer_count = 1


    # here ten postcode links
    for i in result_list:
        print('Started thread No. ' + str(outer_count))
        t = threading.Thread(target=final_function, args=i)
        threads.append(t)
        t.start()
        outer_count += 1
</code></pre>

<p>i is a sublist of links, from which I can get housing data, its length is ten, which is why I get an exception </p>

<pre><code>Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
TypeError: final_function() takes 1 positional argument but 10 were given
</code></pre>

<p>is there anyway I could skip past this? Im stuck out of ideas as I thought simply passing that as an argument would make sense</p>

<p>EDIT: solved myself, I dont know why but all you need to do is </p>

<pre><code>t = threading.Thread(target=final_function, args=(i,)) 
</code></pre>

<p>which solves it </p>

<p><code>args</code> in <code>threading.Thread</code> is supposed be a tuple of arguments, which means that when you pass iterable (list) to it, it considers every list element as separate argument.</p>

<p>It can be avoided by passing tuple, containing a list, to <code>args</code>, like</p>

<pre><code>for i in result_list:
    t = threading.Thread(target=final_function, args=(i,))
</code></pre>

python multithreading