So I have some simple code that is using multithreading. It's working just fine however I'm noticing that the threads aren't being destroyed after returning the values since everytime the script runs, the Thread number in console goes up and the RAM being used also goes up after the script is done processing (which implies that something was left running after the script was done processing).
I've researched this, this, this and asking this. Can anyone suggest what could be going wrong?
if __name__ == "__main__":
def run_selenium1(a, b, c, d, e):
@st.cache_data(show_spinner=False)
def get_links(i, resumeContent):
#stufff happens
for something1, something2, something3, something4, something5, something6, something7 in zip(Final_Something1, Final_Something2, Final_Something3, Final_Something4, Final_Something5, Final_Something6, Final_Something7):
Final_Array.append((something1, something2, something3, something4, something5, something6, something7))
driver.close()
driver.quit()
except:
driver.close()
driver.quit()
with webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) as driver:
try:
#links are obtained
except:
driver.close()
driver.quit()
threads = []
for i in links:
t = threading.Thread(target=get_links, args=(i, Content))
t.daemon = True
threads.append(t)
t.start()
for t in threads:
t.join()
print("Threads destroyed") #<---- this isn't printed
EDIT: Thread Executor approach
with ThreadPoolExecutor(max_workers=25) as executor:
for i in links:
task = executor.submit(get_links, i, resumeContent)
task.join()
executor.shutdown()