Skip to content

Commit

Permalink
runner.docker: Appease mypy and avoid redefining the type of "limits"
Browse files Browse the repository at this point in the history
Mypy really doesn't like redefinitions¹, and we start with List[str] but
then convert to List[int].  The limited support for redefinition
(--allow-redefinition) doesn't apply here because two different code
blocks are involved.

This particular shift of code into the try block doesn't impact the
handling of exceptions.

¹ python/mypy#1174
  • Loading branch information
tsibley committed Mar 9, 2022
1 parent 808ccd6 commit 83d83ce
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions nextstrain/cli/runner/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,22 @@ def test_memory_limit():
status: RunnerTestResultStatus = ...

if image_exists():
def int_or_none(x):
try:
return int(float(x))
except ValueError:
return None

report_memory = """
awk '/^MemTotal:/ { print $2 * 1024 }' /proc/meminfo
(cat /sys/fs/cgroup/memory.max || cat /sys/fs/cgroup/memory/memory.limit_in_bytes) 2>/dev/null
"""

try:
limits = run_bash(report_memory)
limits = list(filter(None, map(int_or_none, run_bash(report_memory))))
except (OSError, subprocess.CalledProcessError):
pass
else:
def int_or_none(x):
try:
return int(float(x))
except ValueError:
return None

limits = list(filter(None, map(int_or_none, limits)))

if limits:
limit = min(limits)

Expand Down

0 comments on commit 83d83ce

Please sign in to comment.