class MPDigitCaptcha(DigitCaptcha): """ Handles multi-process captcha image generation """ def __init__(self, font_paths, h, w, num_digit_min, num_digit_max, num_processes, max_queue_size): """ Parameters ---------- font_paths: list of str List of path to ttf font files h: int height of the generated image w: int width of the generated image num_digit_min: int minimum number of digits in generated captcha image num_digit_max: int maximum number of digits in generated captcha image num_processes: int Number of processes to spawn max_queue_size: int Maximum images in queue before processes wait """ super(MPDigitCaptcha, self).__init__(font_paths, h, w, num_digit_min, num_digit_max) self.mp_data = MPData(num_processes, max_queue_size, self._gen_sample) def start(self): """ Starts the processes """ self.mp_data.start() def get(self): """ Get an image from the queue Returns ------- np.ndarray A captcha image, normalized to [0, 1] """ return self.mp_data.get() def reset(self): """ Resets the generator by stopping all processes """ self.mp_data.reset()
def __init__(self, font_paths, h, w, num_digit_min, num_digit_max, num_processes, max_queue_size): """Parameters ---------- font_paths: list of str List of path to ttf font files h: int height of the generated image w: int width of the generated image num_digit_min: int minimum number of digits in generated captcha image num_digit_max: int maximum number of digits in generated captcha image num_processes: int Number of processes to spawn max_queue_size: int Maximum images in queue before processes wait """ super(MPDigitCaptcha, self).__init__(font_paths, h, w, num_digit_min, num_digit_max) self.mp_data = MPData(num_processes, max_queue_size, self._gen_sample)