Skip to content

Commit c39741b

Browse files
committed
simplify get_max_open_Files()
1 parent 892008f commit c39741b

4 files changed

Lines changed: 12 additions & 17 deletions

File tree

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
%% python.get_max_open_files Get process open-file soft limit via Python
22
function omax = get_max_open_files()
33

4-
omax = [];
4+
omax = missing;
55

66
if ispc()
7-
omax = uint64(omax);
8-
return
7+
return
98
end
109

1110
try
1211
% RLIMIT_NOFILE soft limit is the active per-process descriptor cap.
1312
lim = py.resource.getrlimit(py.resource.RLIMIT_NOFILE);
14-
omax = lim(1);
13+
omax = uint64(lim(1));
1514
catch e
1615
pythonException(e)
17-
omax = [];
16+
omax = missing;
1817
end
1918

20-
omax = uint64(omax);
21-
2219
end
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
%% shell.get_max_open_files Get process open-file soft limit via shell
22
function omax = get_max_open_files()
33

4-
omax = [];
4+
omax = missing;
55

66
if ~ispc()
77

88
[s, m] = system('ulimit -n');
99
if s == 0
10-
omax = str2double(strtrim(m));
10+
o = str2double(strtrim(m));
1111

12-
if ~isfinite(omax) || omax <= 0
13-
omax = [];
12+
if isfinite(o) && o > 0
13+
omax = uint64(o);
1414
end
1515
end
1616

1717
end
1818

19-
omax = uint64(omax);
20-
2119
end

+stdlib/get_max_open_files.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
backend (1,:) string = ["python", "shell"]
88
end
99

10-
omax = uint64([]);
10+
omax = missing;
1111

1212
for b = backend
1313
switch b
@@ -21,7 +21,7 @@
2121
error('stdlib:get_max_open_files:ValueError', 'Unknown backend: %s', b)
2222
end
2323

24-
if ~isempty(omax)
24+
if ~ismissing(omax)
2525
return
2626
end
2727
end

test/TestDisk.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function test_disk_capacity(tc, Ps, B_jdps)
6262
function test_ulimit(tc, B_ps)
6363
[i, b] = stdlib.get_max_open_files(B_ps);
6464
tc.assertMatches(b, B_ps)
65-
tc.verifyClass(i, 'uint64')
6665
if ispc() || (B_ps == "python" && ~stdlib.has_python())
67-
tc.verifyEmpty(i)
66+
tc.verifyEqual(i, missing)
6867
else
68+
tc.verifyClass(i, 'uint64')
6969
tc.verifyGreaterThan(i, 0)
7070
end
7171
end

0 commit comments

Comments
 (0)