У меня есть метод 1, в котором цикл выполняется и вызывает другой метод 2, но я хочу знать, что как я могу вызвать метод 2 параллельно, так как он выполняет некоторые последовательные шаги, и вызов-1 метода 2 должен быть отделен отвызов 2 метода 2 ... так вот мой код Метод 2
def upload_image(img):
sess = requests.Session()
sess.verify = False
start_upload_response = requests.post('https://awsimgproc.com/start_upload', data={"album_id36": 1}, verify=False)
start_upload_response.raise_for_status()
result = start_upload_response.json()
our_upload = result['upload_id36']
url = 'https://awsimgproc.com/uploadImage'
files = {'file': open(img, 'rb')}
data = {'upload_id36':our_upload}
# This makes the post requests async
global api_response
api_response.append(grequests.post(url,data=data,files=files))
Метод 1
def image_generator():
# Change here the location of iamge file
image_file_location = "/home/gaurav/Pictures/sofa-3"
extension = ".jpg"
i=1
img = Image.open(image_file_location + extension)
start_time = datetime.now()
# can change minutes as per need i.e for how much you need run
test suite
end_time = start_time + timedelta(minutes=1)
while start_time < end_time:
# change current image and randomly roating the image
rotated_image = img.rotate(random.randint(1,1000))
new_image_loaction = image_file_location+str(i)+extension
rotated_image.save(new_image_loaction)
# upload the newly rotated image
upload_image(new_image_loaction)
# uncomment this line to add sleep to your method
# time.sleep(random.randint(1,5))
start_time = datetime.now()
i += 1