Skip to content

Commit 4435c8a

Browse files
committed
Try to cleanup mac executor even more
1 parent 25207b3 commit 4435c8a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

.github/workflows/run_code_checks.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@ jobs:
4040
HTTPBIN_URL: 'asd'
4141

4242
steps:
43-
- name: Disable Spotlight indexing
43+
- name: Os cleanup
4444
if: runner.os == 'macOS'
45-
run: sudo mdutil -i off /
45+
run: |
46+
sudo mdutil -i off /
47+
sudo killall ecosystemanalyticsd
48+
sudo killall Finder || true
49+
sudo killall mds || true
50+
sudo killall mds_stores || true
51+
sudo killall mds_worker || true
52+
sudo killall mdworker || true
53+
sudo killall mdworker_shared || true
4654
4755
- name: Checkout repository
4856
uses: actions/checkout@v4

src/crawlee/_utils/system.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from contextlib import suppress
66
from datetime import datetime, timezone
77
from logging import getLogger
8+
from subprocess import run
89
from typing import Annotated
910

1011
import psutil
@@ -96,7 +97,10 @@ def get_cpu_info() -> CpuInfo:
9697

9798
cpu_percent = psutil.cpu_percent(percpu=True)
9899
logger.info(f'Calling get_cpu_info()...: {cpu_percent}')
99-
return CpuInfo(used_ratio=sum(cpu_percent)/len(cpu_percent) / 100)
100+
ratio = sum(cpu_percent)/len(cpu_percent) / 100
101+
if ratio>0.95:
102+
print_ps()
103+
return CpuInfo(used_ratio=ratio)
100104

101105

102106
def get_memory_info() -> MemoryInfo:
@@ -124,3 +128,7 @@ def get_memory_info() -> MemoryInfo:
124128
current_size=ByteSize(current_size_bytes),
125129
system_wide_used_size=ByteSize(vm.total - vm.available),
126130
)
131+
132+
133+
def print_ps():
134+
run("ps -awxo pid,%cpu,comm", shell=True)

tests/unit/crawlers/_basic/test_basic_crawler.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from crawlee._request import Request, RequestState
2424
from crawlee._types import BasicCrawlingContext, EnqueueLinksKwargs, HttpMethod
2525
from crawlee._utils.robots import RobotsTxtFile
26+
from crawlee._utils.system import print_ps
2627
from crawlee.configuration import Configuration
2728
from crawlee.crawlers import BasicCrawler
2829
from crawlee.errors import RequestCollisionError, SessionError, UserDefinedErrorHandlerError
@@ -1293,11 +1294,7 @@ async def test_timeout_in_handler(sleep_type: str, _) -> None:
12931294
from asyncio import timeout # type:ignore[attr-defined] # noqa: PLC0415
12941295

12951296
# Debug CPu usage before starting the test
1296-
run("ps -ewfaxo comm,user,pid,%cpu,cmd", shell=True)
1297-
1298-
run("ps -awxo pid,%cpu,comm", shell=True)
1299-
1300-
1297+
print_ps()
13011298

13021299
handler_timeout = timedelta(seconds=1)
13031300
max_request_retries = 3

0 commit comments

Comments
 (0)