I want to lower the time it takes for a for loop to complete using multiprocessing but I am not sure how to go about it explicitly as I have not seen any clear basic usage pattern for the module that I can apply to this code.
allLines = fileRead.readlines()
allLines = [x.strip() for x in allLines]
for i in range (0,len(allLines)):
currentWord = allLines[currentLine]
currentLine += 1
currentURL = URL+currentWord
uClient = uReq(currentURL)
pageHTML = uClient.read()
uClient.close()
pageSoup = soup(pageHTML,'html.parser')
pageHeader = str(pageSoup.h1)
if 'Sorry!' in pageHeader:
with open(fileA,'a') as fileAppend:
fileAppend.write(currentWord + '\n')
print(currentWord,'available')
else:
print(currentWord,'taken')
EDIT: New code but it's still broken...
allLines = fileRead.readlines()
allLines = [x.strip() for x in allLines]
def f(indexes, allLines):
for i in indexes:
currentWord = allLines[currentLine]
currentLine += 1
currentURL = URL+currentWord
uClient = uReq(currentURL)
pageHTML = uClient.read()
uClient.close()
pageSoup = soup(pageHTML,'html.parser')
pageHeader = str(pageSoup.h1)
if 'Sorry!' in pageHeader:
with open(fileA,'a') as fileAppend:
fileAppend.write(currentWord + '\n')
print(currentWord,'available')
else:
print(currentWord,'taken')
for i in range(threads):
indexes = range(i*len(allLines), i*len(allLines)+threads, 1)
Thread(target=f, args=(indexes, allLines)).start()