我必须在翻新中开发具有指数补偿的重试机制,但是对于不同的API调用,我有不同的重试次数和基本延迟,如何在翻新中实现呢?同时可以有多个api调用如何处理。
当前一个调用执行重试时,重试计数将被第二个api调用替换。
from PIL import Image
import cv2
import sys
from hashlib import md5
import numpy as np
def hashIm(im):
imP = np.array(Image.open(im))
# Convert to BGR and drop alpha channel if it exists
imP = imP[..., 2::-1]
# Make the array contiguous again
imP = np.array(imP)
im = cv2.imread(im)
diff = im.astype(int)-imP.astype(int)
cv2.imshow('cv2', im)
cv2.imshow('PIL', imP)
cv2.imshow('diff', np.abs(diff).astype(np.uint8))
cv2.imshow('diff_overflow', diff.astype(np.uint8))
with open('dist.csv', 'w') as outfile:
diff = im-imP
for i in range(-256, 256):
outfile.write('{},{}\n'.format(i, np.count_nonzero(diff==i)))
cv2.waitKey(0)
cv2.destroyAllWindows()
return md5(im).hexdigest() + ' ' + md5(imP).hexdigest()
if __name__ == '__main__':
print(hashIm('img.jpg'))