I am building a web scraper to scan the inventory of webpages. The script first reads a CSV file and imports items that have been scraped in previous sessions. Then it parses the webpages infinitely until I need it to stop. Which is not known beforehand. I have written a While True loop to achieve this. After this loop, it should add any new items that have been scraped to the existing CSV and save them.
However, I have not found a way to properly exit this infinite loop without losing any of the data it has scraped. I have tried everything on this topic: Ending an infinite while loop but it has not worked in my case.
I run my program in Powershell, and whenever I try ctrl + c, it just does not respond. ctrl + pause/break seems to work, but it stops the whole script immediately, without saving anything.
Edit: added code, the code runs just fine, I just can't exit it.
2nd Edit: Added minimal version of code.
from threading import Thread
def looping():
while True:
try:
print("looping")
except KeyboardInterrupt:
print("Interrupted")
break
threads = []
for i in range(3):
t = Thread(target=looping)
t.start()
threads.append(t)
for thread in threads:
thread.join()