Mutlithreading python
<p>I am new to Python coding and new to stackoverflow as well need your guidance:</p>

<p>I am trying to create AMI of EC2 instances using python. I need to implement multi threading so that AMI creation can run in parallel. But below code is not working. It is creating single AMI at a time.</p>

<p>module1</p>

<pre><code>from Libpy import Libpy
import boto.ec2
import sys
if __name__=='__main__':

  a = B()
  Libpy().multithreading(ec2list1,a.create_amibkp(ec2listname,ec2list1))
</code></pre>

<p>module2</p>

<pre><code>import threading
import time

class Libpy:

    def multithreading(l, function):
        threads = []
        for z,v in enumerate(l):
            dummy = z
            t = threading.Thread(target=function, args=(v,))
            threads.append(t)
            t.start()
</code></pre>

<ol>
<li>ec2listname  - contains the list of instance names for whom AMI
creation should be done </li>
<li>ec2list1 - contains the list of instance ids for whom AMI creation should be done </li>
<li>create_amibkp - customized function which takes AMI for the filtered instances From module1, I am calling module2 to multithread the function but it is not working. It is creating AMI one at time. 
4.B() - class will return ec2listname and ec2list1</li>
</ol>

<p>I can't reproduce your example but I've created a dummy version:</p>

<pre><code>import sys
import threading
import time
import random

random.seed(1)


class Libpy:

    def multithreading(self, lst, function):
        threads = []
        for v in lst:
            t = threading.Thread(target=function, args=(v,))
            t.start()
            threads.append(t)

        for t in threads:
            t.join()


def ami_creation(v):
    t = random.random() * 4
    print("creating ami {0}, sleeping {1}".format(v, t))
    time.sleep(t)
    print("ami {0} created ok".format(v))

ec2list1 = ["ec2-small", "ec2-medium", "ec2-large"]
Libpy().multithreading(ec2list1, ami_creation)

print("All boxes have been created...")
</code></pre>

<p>In the above example the main thread would wait till all boxes are created</p>

python amazon-web-services ami