I am not sure how to do multithreading and after reading a few stackoverflow answers, I came up with this. Note: Python 2.7
from multiprocessing.pool import ThreadPool as Pool
pool_size=10
pool=Pool(pool_size)
for region, directory_ids in direct_dict.iteritems():
    for dir in directory_ids:  
        try:
            async_result=pool.apply_async(describe_with_directory_workspaces, (region, dir, username))
            result=async_result.get()
            code=result[0]      
            content=result[1]
        except Exception as e:
            print "Some error happening"
            print e
        if code==0:
            if content:
                 new_content.append(content)
            else:
                 pass
        else:
            return error_html(environ, start_response, content)
What I am trying to do here is calling describe_with_directory_workspaces with different parameters of region and directories and run it in parallel so that I get the data quickly in new content. Currently, it is going in series which is what giving slow performance to end user.
Am I doing it right? Or is there some better way to do it? How can I confirm that I am getting the multithreading running as I expected it to?
 
     
     
     
     
    