I am trying to create a method that will create threads and send them into a thread pool. How do I stop individual threads after creating them? edit: This is being used for webscraping and will need to be ran in the background for days, it will be a dynamic number of processes and a number of other tasks(I only added 1 for reference. I also do not want the process to end upon completion (will loop the task) only to end upon user request
def Target(web,delay):
log = ("starting")
# gives headless option to chromedriver
op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(options=op)
# launches driver with desired webpage
driver.get(web)
log = ("getting webpage")
while [False != True]:
try:
#test to check if on correct page
#looking for matching key
log = ("checking stock")
elem = driver.find_element_by_xpath('//*[@id="viewport"]/div[5]/div/div[2]/div[3]/div[1]/div/div[3]/div[1]/div[2]/button')
if elem.is_displayed():
log = ("instock")
title= driver.title
url= driver.current_url
return (title, url)
except NoSuchElementException:
print("product is not in stock.... trying again")
#retry delay
time.sleep(float(delay))
driver.get(web)
def multimethodv2(MethodToRun, url, delay,id):
if __name__ == "__main__":
pool = ThreadPoolExecutor()
pool.submit(Target,url,delay)