I didn't use multi-threading so far as I didn't need to. But as far as I've read, implementing them will make my program slightly faster than it actually is.
from validate_email import validate_email
import os
# the program is reading each line from "emails.txt" and after it checks each email it will remove duplicates and sort the godd / bad emails
def verify_emails(all_emails_file, all_good_emails_file, all_bad_emails_file):
with open(all_emails_file) as f: all_emails = f.readlines()
rs_emails = [elem.strip('\n') for elem in all_emails]
rs_emails_set = set(rs_emails) # remove duplicates
good_emails_file, bad_emails_file = open(all_good_emails_file, 'w+'), open(all_bad_emails_file, 'w+')
for email in rs_emails_set:
if validate_email(email, verify=True):
print >> good_emails_file, email
else:
print >> bad_emails_file, email
if __name__ == "__main__":
clear = lambda: os.system('cls')
clear()
try:
verify_emails("emails.txt", "good_emails.txt", "bad_emails.txt")
except:
print "\n\nFile with emails could not be found. Please create emails.txt and run the program again\n\n"
My code is perfectly functional, but when it handles big files ( > 2k rows ) it runs really slow. I'd like to take the best out of it and make it as faster as possible using multi-threading or any other methods.
I'd like when answering, if possible, somebody to explain me whether using multi-threading will help me optimize the program or not. More, I'd like somebody to also explain from his / her experience how can I optimize my code