zenx 0.10.0__py3-none-any.whl → 0.10.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zenx/engine.py +17 -5
- {zenx-0.10.0.dist-info → zenx-0.10.2.dist-info}/METADATA +1 -1
- {zenx-0.10.0.dist-info → zenx-0.10.2.dist-info}/RECORD +6 -6
- {zenx-0.10.0.dist-info → zenx-0.10.2.dist-info}/WHEEL +0 -0
- {zenx-0.10.0.dist-info → zenx-0.10.2.dist-info}/entry_points.txt +0 -0
- {zenx-0.10.0.dist-info → zenx-0.10.2.dist-info}/top_level.txt +0 -0
zenx/engine.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import asyncio
|
2
2
|
import signal
|
3
|
-
from typing import List
|
3
|
+
from typing import List, Optional
|
4
4
|
from dotenv import load_dotenv
|
5
5
|
import pebble
|
6
6
|
import uvloop
|
@@ -26,7 +26,7 @@ class Engine:
|
|
26
26
|
self.shutdown_event.set()
|
27
27
|
|
28
28
|
|
29
|
-
async def
|
29
|
+
async def _execute_spider(self, spider_name: str) -> None:
|
30
30
|
loop = asyncio.get_running_loop()
|
31
31
|
loop.add_signal_handler(signal.SIGINT, self._shutdown_handler)
|
32
32
|
loop.add_signal_handler(signal.SIGTERM, self._shutdown_handler)
|
@@ -47,29 +47,41 @@ class Engine:
|
|
47
47
|
await pm.start_pipelines()
|
48
48
|
|
49
49
|
spider = spider_cls(client=client, pm=pm, logger=logger, settings=settings)
|
50
|
+
crawl_task: Optional[asyncio.Task] = None
|
50
51
|
try:
|
51
52
|
if self.forever:
|
52
53
|
while not self.shutdown_event.is_set():
|
54
|
+
crawl_task = asyncio.create_task(spider.crawl())
|
53
55
|
try:
|
54
|
-
await
|
56
|
+
await crawl_task
|
55
57
|
except Exception:
|
56
58
|
logger.exception("crawl")
|
57
59
|
await asyncio.sleep(0.01)
|
58
60
|
else:
|
59
|
-
|
61
|
+
crawl_task = asyncio.create_task(spider.crawl())
|
62
|
+
await crawl_task
|
60
63
|
finally:
|
61
64
|
if self.shutdown_event.is_set():
|
62
65
|
logger.info("shutdown", spider=spider_name)
|
66
|
+
|
67
|
+
if crawl_task and not crawl_task.done():
|
68
|
+
crawl_task.cancel()
|
69
|
+
logger.debug("cancelled", task="crawl")
|
70
|
+
try:
|
71
|
+
await crawl_task
|
72
|
+
except asyncio.CancelledError:
|
73
|
+
pass
|
63
74
|
if spider.background_tasks:
|
64
75
|
logger.debug("waiting", background_tasks=len(spider.background_tasks), belong_to="spider")
|
65
76
|
await asyncio.gather(*spider.background_tasks)
|
77
|
+
|
66
78
|
await client.close()
|
67
79
|
await db.close()
|
68
80
|
await pm.close_pipelines()
|
69
81
|
|
70
82
|
|
71
83
|
def run_spider(self, spider: str) -> None:
|
72
|
-
uvloop.run(self.
|
84
|
+
uvloop.run(self._execute_spider(spider))
|
73
85
|
|
74
86
|
|
75
87
|
def run_spiders(self, spiders: List[str]) -> None:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
zenx/cli.py,sha256=pHKhOTdqI6NQQoYK91waRIMpxCXLYtXEryzVaTbmvqc,2810
|
2
2
|
zenx/debug_runner.py,sha256=B2Jd9A4_EHDa-ohLcwnFIxOV73FagTWXX2fl3qgwlpY,809
|
3
3
|
zenx/discovery.py,sha256=YANVGzy2IG1fYruUud-11Y-ynyO6iEp3EjlHnhIQJQI,1014
|
4
|
-
zenx/engine.py,sha256=
|
4
|
+
zenx/engine.py,sha256=rcrVrXdKORLST648XxGmC8sI54i1IVD32HccxGB0bxU,3028
|
5
5
|
zenx/exceptions.py,sha256=BJXxzwwX2CU6inhppfblx8c8Z6Mhvsk7MAhQ1LAnhBg,37
|
6
6
|
zenx/logger.py,sha256=lr45XGbV769NQcwn8-lAcPfFbR4yBN8LNh7o-i4Aa9M,1652
|
7
7
|
zenx/settings.py,sha256=anTT_jSQxwIabBHCM7egYFUOnALxp4fF_26_2ZPtTt4,1044
|
@@ -21,8 +21,8 @@ zenx/resources/proto/feed_pb2.py,sha256=ZyICOLnyuXekkvV4bAHZ1nE1-wwzcYYRRrmRJCMr
|
|
21
21
|
zenx/resources/proto/feed_pb2_grpc.py,sha256=Mim6FfBgIMj0PmTqHk036nVUMJH3A6I3ts6r1j3bQF8,7441
|
22
22
|
zenx/spiders/__init__.py,sha256=rs5LuqdM2MQlUYiTGJrzkYhzN8_SSLTrR7wGjSRrrSo,25
|
23
23
|
zenx/spiders/base.py,sha256=MeZ3wZOPOyOX4V2ufFXtYGCDtXHZO_mNfnXdKMkisuQ,1951
|
24
|
-
zenx-0.10.
|
25
|
-
zenx-0.10.
|
26
|
-
zenx-0.10.
|
27
|
-
zenx-0.10.
|
28
|
-
zenx-0.10.
|
24
|
+
zenx-0.10.2.dist-info/METADATA,sha256=6qMTNCG09Dd7MaVcaMSsnMPP_0NKSYuwo1VOKv2q_LA,1422
|
25
|
+
zenx-0.10.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
26
|
+
zenx-0.10.2.dist-info/entry_points.txt,sha256=8JXob2f1VtvzGFris-e9Usqywg7oca-cChDlH9moOZU,38
|
27
|
+
zenx-0.10.2.dist-info/top_level.txt,sha256=JeXwvK86d7sB-2x-avugFnZIZa33zaHWKI8RHWJR6KY,5
|
28
|
+
zenx-0.10.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|