title: trying to split the file download buffer to into separate threads
body: <p>I am trying to download the buffer of file into 5 threads but it seems like it's getting garbled.</p>
  
  <pre><code>from numpy import arange
  import requests
  from threading import Thread
  import urllib2
  
  url = 'http://pymotw.com/2/urllib/index.html'
  sizeInBytes = r = requests.head(url, headers={'Accept-Encoding': 'identity'}).headers['content-length']
  
  splitBy = 5
  
  splits = arange(splitBy + 1) * (float(sizeInBytes)/splitBy)
  
  dataLst = []
  
  def bufferSplit(url, idx, splits):
      req = urllib2.Request(url,  headers={'Range': 'bytes=%d-%d' % (splits[idx], splits[idx+1])})
      print {'bytes=%d-%d' % (splits[idx], splits[idx+1])}
      dataLst.append(urllib2.urlopen(req).read())
  
  
  for idx in range(splitBy):
      dlth = Thread(target=bufferSplit, args=(url, idx, splits))
      dlth.start()
  
  
  print dataLst
  
  with open('page.html', 'w') as fh:
      fh.write(''.join(dataLst))
  </code></pre>
  
  <p><strong>Update:</strong> 
  So I worked over and got little but progress, however if I download a jpg it seems to be corrupted;</p>
  
  <pre><code>from numpy import arange
  import os
  import requests
  import threading
  import urllib2
  
  # url ='http://s1.fans.ge/mp3/201109/08/John_Legend_So_High_Remix(fans_ge).mp3'
  url = "http://www.nasa.gov/images/content/607800main_kepler1200_1600-1200.jpg"
  # url = 'http://pymotw.com/2/urllib/index.html'
  sizeInBytes = requests.head(url, headers={'Accept-Encoding': 'identity'}).headers.get('content-length', None)
  
  
  splitBy = 5
  
  dataLst = []
  
  
  class ThreadedFetch(threading.Thread):
      """ docstring for ThreadedFetch
      """
      def __init__(self, url, fileName, splitBy=5):
          super(ThreadedFetch, self).__init__()
          self.__url = url
          self.__spl = splitBy
          self.__dataLst = []
          self.__fileName = fileName
  
      def run(self):
          if not sizeInBytes:
              print "Size cannot be determined."
              return
          splits = arange(self.__spl + 1) * (float(sizeInBytes)/self.__spl)
          for idx in range(self.__spl):
              req = urllib2.Request(self.__url,  headers={'Range': 'bytes=%d-%d' % (splits[idx], splits[idx+1])})
              self.__dataLst.append(urllib2.urlopen(req).read())
  
  
      def getFileData(self):
          return ''.join(self.__dataLst)
  
  
  fileName = url.split('/')[-1]
  
  dl = ThreadedFetch(url, fileName)
  dl.start()
  dl.join()
  content = dl.getFileData()
  if content:
      with open(fileName, 'w') as fh:
          fh.write(content)
      print "Finished Writing file %s" % fileName
  </code></pre>
  
  <p>Below is how the image after getting downloaded.</p>
  
  <p><img src="https://i.stack.imgur.com/hgrMi.jpg" alt="corrupted image"></p>