0

I have to test about one million possible urls. If the url is valid I want to store it in a CSV. To speed things up I want to use asynchronously. Code works fine when ran with a for loop, but the CSV is empty if I run it asynchronously.

    #Declare CSV
import csv
csvFile = open('example.tsv', 'w', newline='')
    csvWriter = csv.writer(csvFile, delimiter='\t', lineterminator='\n\n')

    def parse(url):
        #get url's <title>
        data = getTitle(url)
        #if record is found

        if(data.title.string != "RECORD INACTIVE" or data.title.string != "FOUND"):
            csvWriter.writerow([url])


    with ProcessPoolExecutor(max_workers=4) as executor:
        {executor.submit(parse, url): url for url in URLS} 

When I run this Asunchronously the CSV file is empty.

But it works if I run it with a fro loop :

for url in URLS:
    parse(ul)
Lev
  • 999
  • 2
  • 10
  • 26

0 Answers0