Skip to content
Open
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
3 changes: 2 additions & 1 deletion nemo_run/core/execution/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def run(self, client: "DockerClient", id: str) -> "Container":
if self.executor.ulimits:
ulimits = []
for ulimit in self.executor.ulimits:
vals = ulimit.split(":")
# Accept the documented <type>=<soft>[:<hard>] form as well as <type>:<soft>[:<hard>].
vals = ulimit.replace("=", ":", 1).split(":")
name = vals[0]
soft = vals[1]
hard = vals[2] if len(vals) > 2 else vals[1]
Expand Down
23 changes: 23 additions & 0 deletions test/core/execution/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,29 @@ def mocked_run(*args, **kwargs):
assert container.extra_env == {"EXTRA": "value"}
assert container.executor.experiment_id == "exp123"

@pytest.mark.parametrize(
"ulimit, expected",
[
("memlock=-1", ("memlock", -1, -1)),
("nofile=1024:2048", ("nofile", 1024, 2048)),
("stack=67108864", ("stack", 67108864, 67108864)),
("memlock:0:123", ("memlock", 0, 123)),
("nofile:1024", ("nofile", 1024, 1024)),
],
)
@patch("nemo_run.core.execution.docker.ensure_network")
def test_run_parses_ulimits(self, mock_ensure_network, mock_docker_client, ulimit, expected):
executor = DockerExecutor(container_image="test:latest", ulimits=[ulimit])
executor.experiment_id = "exp123"
container = DockerContainer(
name="test-container", command=["python", "script.py"], executor=executor, extra_env={}
)

container.run(mock_docker_client, "job123")

(parsed,) = mock_docker_client.containers.run.call_args.kwargs["ulimits"]
assert (parsed.name, parsed.soft, parsed.hard) == expected

def test_get_container(self, mock_docker_client, mock_container):
"""Test get_container method."""
executor = DockerExecutor(container_image="test:latest")
Expand Down