Skip to content

Commit 9bb1c12

Browse files
committed
Close and Remove Log File Handler
Properly close log file handler before jumping to new site to avoid writing log on wrong directory where it was originally written. This ensures that the logging jumps to respective website it's processing.
1 parent 0f01b79 commit 9bb1c12

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

scraper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def main():
6262
with ChDir(batch_website):
6363
start_page = get_start_page()
6464

65-
setup_rotating_log(batch_website, seed)
65+
handler = setup_rotating_log(batch_website, seed)
6666

6767
with ChDir(batch_website):
6868
crawl(seed, pbar[idx], start_page, planned_urls_array, crawled_urls_array, website, max_pages)
6969
overall_prog.update(1)
70+
handler.close()
71+
logger.removeHandler(handler)
7072

7173
def setup_rotating_log(batch_website, seed):
7274
with ChDir(batch_website):
@@ -85,6 +87,7 @@ def setup_rotating_log(batch_website, seed):
8587
backupCount=100
8688
)
8789
logger.addHandler(handler)
90+
return handler
8891

8992
def crawl(seed, prog_upd, start_page, planned_urls_array, crawled_urls_array, website, max_pages):
9093
"""Function that takes link, saves the contents to text file call href_split

0 commit comments

Comments
 (0)