Skip to content

Support peak_measured_mem on Windows #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cubed/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import platform
import random
from functools import partial

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


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

Expand Down
10 changes: 0 additions & 10 deletions cubed/tests/test_executor_features.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import os
import platform
import re

import fsspec
Expand Down Expand Up @@ -72,9 +71,6 @@ def mock_apply_blockwise(*args, **kwargs):


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


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


@pytest.mark.skipif(
platform.system() == "Windows", reason="measuring memory does not run on windows"
)
def test_mem_warn(tmp_path, executor):
if executor.name not in ("processes", "lithops"):
pytest.skip(f"{executor.name} executor does not support MemoryWarningCallback")
Expand Down
2 changes: 0 additions & 2 deletions cubed/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import inspect
import itertools
import platform

import numpy as np
import pytest
Expand Down Expand Up @@ -92,7 +91,6 @@ def test_memory_repr():
memory_repr(-1)


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

Expand Down
17 changes: 6 additions & 11 deletions cubed/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import platform
from typing import Iterable

import networkx as nx
Expand All @@ -18,18 +17,14 @@
"localhost": {"version": 1},
}

ALL_EXECUTORS = [create_executor("single-threaded")]
ALL_EXECUTORS = [
create_executor("single-threaded"),
create_executor("threads"),
create_executor("processes"),
]

# don't run all tests on every executor as it's too slow, so just have a subset
MAIN_EXECUTORS = [create_executor("single-threaded")]


if platform.system() != "Windows":
# ThreadsExecutor calls `peak_measured_mem` which is not supported on Windows
ALL_EXECUTORS.append(create_executor("threads"))

ALL_EXECUTORS.append(create_executor("processes"))
MAIN_EXECUTORS.append(create_executor("processes"))
MAIN_EXECUTORS = [create_executor("single-threaded"), create_executor("processes")]

try:
ALL_EXECUTORS.append(create_executor("beam"))
Expand Down
9 changes: 4 additions & 5 deletions cubed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ def memory_repr(num: int) -> str:


def peak_measured_mem() -> int:
"""Measures the peak memory usage in bytes.

Note: this function currently doesn't work on Windows.
"""
"""Measures the peak memory usage in bytes."""

if platform.system() == "Windows":
raise NotImplementedError("`peak_measured_mem` is not implemented on Windows")
import psutil

return psutil.Process().memory_info().peak_wset

from resource import RUSAGE_SELF, getrusage

Expand Down
Loading