-
Notifications
You must be signed in to change notification settings - Fork 20
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
Handle memory limits reported from Docker as floats #159
Conversation
Fixes an issue on Mac OS X with Docker where `check-setup --set-default` fails when the memory limits reported from the Docker OS are in floating point values (e.g., "") that cannot be cast to integers by Python. This commit addresses the issue by first casting the string to float before casting to int. Related to #153
Ugh, sorry about that. Thanks for this fix. I think we should also address the underlying |
I was incredulous that /proc/meminfo reported this in exponential notation, so I dug a bit deeper. Indeed,
Locally this doesn't happen, so presumably there's some newer/different version of awk in the container than I have or maybe some locale-dependent thing. But this as-documented:
The upshot is we could fix this by instead doing the right thing in awk:
But |
Nevermind! This hits the limit of the (signed) long int (2³¹ - 1), which I didn't notice earlier: nextstrain:/nextstrain/build $ grep ^MemTotal: /proc/meminfo
MemTotal: 16181632 kB
nextstrain:/nextstrain/build $ awk '/^MemTotal:/ { print $2 }' /proc/meminfo
16181632
nextstrain:/nextstrain/build $ awk '/^MemTotal:/ { print $2 * 1024 }' /proc/meminfo
1.657e+10
nextstrain:/nextstrain/build $ awk '/^MemTotal:/ { printf("%lu\n", $2 * 1024) }' /proc/meminfo
2147483647
nextstrain:/nextstrain/build $ perl -anE 'say $F[1] * 1024 if /^MemTotal:/' /proc/meminfo
16569991168 Maybe worth ditching the vagaries of awk's numeric handling, even if the exponential notation it produces seems ok on the face of it? I dunno. |
…k-setup Previously if no memory limits could be found, then we effectively called min([]), which is a ValueError. @huddlej's previous commit addressed an issue with exponential notation that could lead to no memory limits being found, but it's still good to guard min() against similar issues in the future. Diff best viewed with whitespace ignored.
Helpful for troubleshooting to see what the found limit was even when it's higher than 2 GiB.
@huddlej Pushed two additional commits addressing my other concern. Would you take a look? |
Agreed about avoiding awk vagaries where possible. It's been ages since I used Perl; will it avoid creating exponential values for the conversion to bytes? The other solution that seems fine is to make two separate system calls to parse
These changes look good to me! Also agree it's better to protect against the empty list in the future. |
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
I'm going to leave it as-is with awk for now to avoid accidentally breaking it another way. I didn't mean to suggest replacing awk with Perl here. Perl will generally avoid creating exponential notation… but I believe only up to a certain point (that's larger than awk's). Two separate |
@huddlej Released with 3.2.0, so you can install that and make |
@tsibley It works! Thank you! |
Context
The fix in #153 produced a new error for me with Docker 4.5.0 on OS X 10.14.6:
Inspecting the values of
limits
in pdb, I find:Since the OS reports the memory limit with an exponential value,
int
cannot interpret the string and returns aValueError
. However,float
can interpret this string, soint(float("4.1257e+09"))
produces4125700000
, as expected.After changing
int_or_none
accordingly, I ran thenextstrain
command again (this time from a local dev installation with my changes).And the command ran as expected.
Description of proposed changes
Fixes the issue described above on Mac OS X with Docker where
check-setup --set-default
fails when the memory limits reported from the Docker OS are in floating point values (e.g., "") that cannot be cast to integers by Python. This commit addresses the issue by first casting the string to float before casting to int.Related issue(s)
Related to #153
Testing