Skip to content

Commit 8ea7186

Browse files
committed
Support peak_measured_mem on Windows
1 parent 4b18053 commit 8ea7186

File tree

5 files changed

+10
-30
lines changed

5 files changed

+10
-30
lines changed

cubed/tests/test_core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import platform
21
import random
32
from functools import partial
43

@@ -595,7 +594,6 @@ def test_array_pickle(spec, executor):
595594
assert_array_equal(c.compute(executor=executor), expected)
596595

597596

598-
@pytest.mark.skipif(platform.system() == "Windows", reason="does not run on windows")
599597
def test_measure_reserved_mem(executor):
600598
pytest.importorskip("lithops")
601599

cubed/tests/test_executor_features.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import contextlib
22
import os
3-
import platform
43
import re
54

65
import fsspec
@@ -72,9 +71,6 @@ def mock_apply_blockwise(*args, **kwargs):
7271

7372

7473
# see tests/runtime for more tests for retries for other executors
75-
@pytest.mark.skipif(
76-
platform.system() == "Windows", reason="measuring memory does not run on windows"
77-
)
7874
def test_retries(mocker, spec):
7975
# Use threads executor since single-threaded executor doesn't support retries
8076
executor = create_executor("threads")
@@ -91,9 +87,6 @@ def test_retries(mocker, spec):
9187
)
9288

9389

94-
@pytest.mark.skipif(
95-
platform.system() == "Windows", reason="measuring memory does not run on windows"
96-
)
9790
def test_callbacks(spec, executor):
9891
task_counter = TaskCounter()
9992
# test following indirectly by checking they don't cause a failure
@@ -149,9 +142,6 @@ def test_callbacks_modal(spec, modal_executor):
149142
fs.rm(tmp_path, recursive=True)
150143

151144

152-
@pytest.mark.skipif(
153-
platform.system() == "Windows", reason="measuring memory does not run on windows"
154-
)
155145
def test_mem_warn(tmp_path, executor):
156146
if executor.name not in ("processes", "lithops"):
157147
pytest.skip(f"{executor.name} executor does not support MemoryWarningCallback")

cubed/tests/test_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inspect
22
import itertools
3-
import platform
43

54
import numpy as np
65
import pytest
@@ -92,7 +91,6 @@ def test_memory_repr():
9291
memory_repr(-1)
9392

9493

95-
@pytest.mark.skipif(platform.system() == "Windows", reason="does not run on windows")
9694
def test_peak_measured_mem():
9795
assert peak_measured_mem() > 0
9896

cubed/tests/utils.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import platform
21
from typing import Iterable
32

43
import networkx as nx
@@ -18,18 +17,14 @@
1817
"localhost": {"version": 1},
1918
}
2019

21-
ALL_EXECUTORS = [create_executor("single-threaded")]
20+
ALL_EXECUTORS = [
21+
create_executor("single-threaded"),
22+
create_executor("threads"),
23+
create_executor("processes"),
24+
]
2225

2326
# don't run all tests on every executor as it's too slow, so just have a subset
24-
MAIN_EXECUTORS = [create_executor("single-threaded")]
25-
26-
27-
if platform.system() != "Windows":
28-
# ThreadsExecutor calls `peak_measured_mem` which is not supported on Windows
29-
ALL_EXECUTORS.append(create_executor("threads"))
30-
31-
ALL_EXECUTORS.append(create_executor("processes"))
32-
MAIN_EXECUTORS.append(create_executor("processes"))
27+
MAIN_EXECUTORS = [create_executor("single-threaded"), create_executor("processes")]
3328

3429
try:
3530
ALL_EXECUTORS.append(create_executor("beam"))

cubed/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ def memory_repr(num: int) -> str:
112112

113113

114114
def peak_measured_mem() -> int:
115-
"""Measures the peak memory usage in bytes.
116-
117-
Note: this function currently doesn't work on Windows.
118-
"""
115+
"""Measures the peak memory usage in bytes."""
119116

120117
if platform.system() == "Windows":
121-
raise NotImplementedError("`peak_measured_mem` is not implemented on Windows")
118+
import psutil
119+
120+
return psutil.Process().memory_info().peak_wset
122121

123122
from resource import RUSAGE_SELF, getrusage
124123

0 commit comments

Comments
 (0)