Replace prints with logging.

This commit is contained in:
Andrey Rakhmatullin 2026-07-17 16:57:52 +05:00
parent 4c7d6bff59
commit 05c085ba9a
2 changed files with 9 additions and 3 deletions

View File

@ -1,9 +1,12 @@
import logging
import sys
import scrapy
from scrapy.crawler import AsyncCrawlerProcess
from scrapy.utils.reactorless import ReactorImportHook
logger = logging.getLogger(__name__)
def hook_count() -> int:
return sum(1 for finder in sys.meta_path if isinstance(finder, ReactorImportHook))
@ -23,4 +26,4 @@ for _ in range(2):
process.crawl(NoRequestsSpider)
process.start()
print(f"Hooks after runs: {hook_count()}", file=sys.stderr)
logger.info(f"Hooks after runs: {hook_count()}")

View File

@ -1,9 +1,12 @@
import logging
import sys
import scrapy
from scrapy.crawler import AsyncCrawlerProcess
from scrapy.utils.reactorless import ReactorImportHook
logger = logging.getLogger(__name__)
class NoRequestsSpider(scrapy.Spider):
name = "no_request"
@ -19,8 +22,8 @@ process.crawl(NoRequestsSpider)
process.start()
hook_count = sum(1 for finder in sys.meta_path if isinstance(finder, ReactorImportHook))
print(f"Hooks in sys.meta_path after start(): {hook_count}", file=sys.stderr)
logger.info(f"Hooks in sys.meta_path after start(): {hook_count}")
import twisted.internet.reactor # noqa: E402,F401,TID253
print("Reactor imported after start()", file=sys.stderr)
logger.info("Reactor imported after start()")