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.
module1
from Libpy import Libpy
import boto.ec2
import sys
if __name__=='__main__':
a = B()
Libpy().multithreading(ec2list1,a.create_amibkp(ec2listname,ec2list1))
module2
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()
- ec2listname - contains the list of instance names for whom AMI creation should be done
- ec2list1 - contains the list of instance ids for whom AMI creation should be done
- 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