I want to fetch multiple mails message, by theirs ids from Gmail and I'm using Imap for that. It worked great until I tried to speed things up with ThreadPull executor (even for 2 executors).
if anyone can think about what is the reason for that problem it will be very helpful.
connector.py
def create_data_models(self, msgs_ids, max_workers=2):
data_models = []
#msgs_id_list = [message['id'] for message in messages]
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {executor.submit(self.imapService.fetch_message, msg_id) : msg_id for msg_id in msgs_ids}
for future in concurrent.futures.as_completed(futures):
try:
data = future.result()
data_model = self._create_msg_obj1(data)
data_models.append(data_model)
except Exception as exc:
print('generated an exception: %s' % (exc))
return data_models
imap_service.py
def fetch_message(self, msg_id):
_, data = self.mail.uid('fetch', msg_id, '(RFC822)')
_, mail_data = data[0]
logger.error('Succesfully fetch message from {} with {} id'.format(self.email_address, msg_id))
print('Succesfully fetch message from {} with {} id'.format(self.email_address, msg_id))
return mail_data
The errors:
generated an exception: command: UID => unexpected response: b'v5oJ8jIW2KPDzS/DHMN+58yL3Q'
generated an exception: command: UID => unexpected response: b'X-Google-Smtp-Source: APXvYqwtp0c9H1jJ8uZTRW5ZBjIyNbqRgeoGUq8heUUf00uNRHW9Nvyl1dTjYZAy6ijzL29+PTL7'
generated an exception: command: UID => unexpected response: b'X-Received: by 2002:a50:9223:: with SMTP id i32mr19845429eda.40.1566127216934;'
generated an exception: command: UID => unexpected response: b' Sun, 18 Aug 2019 04:20:16 -0700 (PDT)'
generated an exception: command: UID => unexpected response: b'le.com; s=arc-20160816;'
generated an exception: command: UID => unexpected response: b' h=message-id:to:sender:from:reply-to:subject:date:mime-version'