title: MultiThreading with a python loop
body: <p>I an trying to run this Python code on several threads of my processor, but I can't find how to allocate multiple threads. I am using <strong>python 2.7</strong> in Jupyter (formerly IPython).
  The initial code is below (all this part works perfectly). It is a web parser which takes <code>x</code> i.e., a url among my_list i.e., a list of url and then write a CSV (where out_string is a line).</p>
  
  <h1>Code without MultiThreading</h1>
  
  <pre><code>my_list = ['http://stackoverflow.com/', 'http://google.com']
  
  def main():
      with open('Extract.csv'), 'w') as out_file:
          count_loop = 0
          for x in my_list:
              #================  Get title ==================#
              out_string = ""
              campaign = parseCampaign(x)
              out_string += ';' + str(campaign.getTitle())
  
              #================ Get Profile ==================#
              if campaign.getTitle() != 'NA':
                  creator = parseCreator(campaign.getCreatorUrl())
                  out_string += ';' + str(creator.getCreatorProfileLinkUrl())
              else:
                  pass
              #================ Write ==================#
              out_string += '\n'
              out_file.write(out_string) 
              count_loop +=1
              print '---- %s on %s ------- ' %(count_loop, len(my_list))
  </code></pre>
  
  <h1>Code with MultiThreading but not working</h1>
  
  <pre><code>from threading import Thread
  my_list = ['http://stackoverflow.com/', 'http://google.com']
  
  def main(x):
      with open('Extract.csv'), 'w') as out_file:
          count_loop = 0
          for x in my_list:
              #================  Get title ==================#
              out_string = ""
              campaign = parseCampaign(x)
              out_string += ';' + str(campaign.getTitle())
  
              #================ Get Profile ==================#
              if campaign.getTitle() != 'NA':
                  creator = parseCreator(campaign.getCreatorUrl())
                  out_string += ';' + str(creator.getCreatorProfileLinkUrl())
              else:
                  pass
              #================ Write ==================#
              out_string += '\n'
              out_file.write(out_string) 
              count_loop +=1
              print '---- %s on %s ------- ' %(count_loop, len(my_list))
  
  for x in my_list:
      t = Thread(target=main, args=(x,))
      t.start()
      t2 = Thread(target=main, args=(x,))
      t2.start()
  </code></pre>
  
  <p>I cannot find a good way to implement more than one thread to run this piece of code, and I am a bit confused because the documentation is not very easy to understand. With one core, this code takes 2 hours long, multi-threading will save me lot of time!</p>