我的目标是:
现在,当我同时运行thread_crawl()和thread_extract()时,thread_extract仅在thread_crawl处于运行中间时才抛出错误,因为它使用了其文件。
这是我当前同时运行两个线程的代码。
def thread_crawl():
while True:
crawl(' ', path)
time.sleep(2)
def thread_extract():
while True:
time.sleep(10)
extract(path)
if __name__ == '__main__':
if not os.path.exists(path + 'archive_dict.pkl'): # performs initial crawl to build archive_dict.pkl (required by article_extractor.py)
crawl(' ', path)
crawler = threading.Thread(target=thread_crawl)
extractor = threading.Thread(target=thread_extract)
crawler.start()
extractor.start()