Skip to content

Commit 1e1e4ce

Browse files
committed
See more detailed CPu measurements
1 parent d3d5c03 commit 1e1e4ce

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/crawlee/_utils/system.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def get_cpu_info() -> CpuInfo:
9393
It utilizes the `psutil` library. Function `psutil.cpu_percent()` returns a float representing the current
9494
system-wide CPU utilization as a percentage.
9595
"""
96-
logger.debug('Calling get_cpu_info()...')
97-
cpu_percent = psutil.cpu_percent(interval=0.1)
96+
97+
cpu_percent = psutil.cpu_percent()
98+
logger.info(f'Calling get_cpu_info()...: {cpu_percent}')
9899
return CpuInfo(used_ratio=cpu_percent / 100)
99100

100101

tests/unit/crawlers/_basic/test_basic_crawler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
from dataclasses import dataclass
1313
from datetime import timedelta
1414
from itertools import product
15+
from subprocess import run
1516
from typing import TYPE_CHECKING, Any, Literal, cast
1617
from unittest.mock import AsyncMock, Mock, call, patch
1718

19+
import psutil
1820
import pytest
1921

2022
from crawlee import ConcurrencySettings, Glob, service_locator
@@ -1290,6 +1292,13 @@ async def test_timeout_in_handler(sleep_type: str, _) -> None:
12901292
# Test is skipped in older Python versions.
12911293
from asyncio import timeout # type:ignore[attr-defined] # noqa: PLC0415
12921294

1295+
# Debug CPu usage before starting the test
1296+
run("ps -efaxo comm,user,cmd,pid,%cpu", shell=True)
1297+
1298+
run("ps -axo pid,comm,%cpu", shell=True)
1299+
1300+
1301+
12931302
handler_timeout = timedelta(seconds=1)
12941303
max_request_retries = 3
12951304
double_handler_timeout_s = handler_timeout.total_seconds() * 2

0 commit comments

Comments
 (0)