From 8798f6d829b424c9aa00ae8a038abc50ef59fae5 Mon Sep 17 00:00:00 2001 From: jiazeh <45085050+jiazeh@users.noreply.github.com> Date: Fri, 13 Aug 2021 14:57:22 +0800 Subject: [PATCH] Update light_spider.py Add a callback function when starting to run. --- fastspider/core/spiders/light_spider.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastspider/core/spiders/light_spider.py b/fastspider/core/spiders/light_spider.py index 01c5a43..9fc475b 100644 --- a/fastspider/core/spiders/light_spider.py +++ b/fastspider/core/spiders/light_spider.py @@ -74,6 +74,7 @@ def run(self): """ 启动线程 """ + self.start_callback() # 先将任务监听的控制方法启动, 再通过add_task将需要爬取的request对象写入, 通过while检测任务执行的情况, 任务执行完, 则暂定任务_thread_stop设置为True for i in range(self._thread_count): spider_controller = LightSpiderController(self._memory_db, self._item_cache) @@ -101,3 +102,6 @@ def run(self): print("无任务, 爬虫执行完毕") break + + self.end_callback() + self._started.clear()