https://pantsbuild.org/ logo
#development
Title
# development
a

average-vr-56795

04/09/2019, 9:51 PM
Damnit Python. Today I learnt that Python is super helpful, and if you call
os.fdopen(fd)
, when it garbage collects the file object that produces, it will automatically close the fd. Which is great as long as nothing else was using that fd.
h

hundreds-father-404

04/09/2019, 9:52 PM
How’d you discover this? Sounds like an intense story
a

aloof-angle-91616

04/09/2019, 9:52 PM
oh hm i think i learned that when i was last looking at output redirection for the pailgun client but quickly forgot it
"batteries included"
a

average-vr-56795

04/09/2019, 9:54 PM
I discovered this by debugging why the second unit test to run that sets the logging output directory of our rust-implemented Python logger would consistently fail.
On the journey I learnt many things.
One of them is that one of the rust logging libraries that we’re using swallows errors. That was not a useful step.
I mean, learning it was useful.
w

witty-crayon-22786

04/09/2019, 9:56 PM
wowee!
a

average-vr-56795

04/09/2019, 9:57 PM
But yeah, apparently simplelog are just like “The API says we can’t return an error, so… Pretend there wasn’t an error?” https://docs.rs/simplelog/0.4.4/src/simplelog/loggers/writelog.rs.html#77
w

witty-crayon-22786

04/09/2019, 9:57 PM
... that's ... a really annoying API.
(the fdopen closing things its been given bit, maybe the other thing too.)
a

average-vr-56795

04/09/2019, 9:57 PM
They are both… Suboptimal 🙂
But now I know 😄
w

witty-crayon-22786

04/09/2019, 10:00 PM
themoreyouknow
a

aloof-angle-91616

04/10/2019, 4:08 AM
the
let _ =
bit really got me
auto-gcing file descriptors is also not at all what i would expect but i actually got less angry about it in general after seeing that the fix was just a dup
if you've dived into fatal error messaging you'll perhaps have seen several points in ExceptionSink and in DaemonSignalHandler where we try desperately to log absolutely anything and refuse to trust that any operation won't raise an io error (or at least, that's the idea)
i wouldn't think there's a "right" way to handle a logging API that doesn't allow propagating errors but silently dropping the result of the
try_log()
without even a comment is heartbreaking to me
so also, thanks for figuring out that you can just dup an fd to stop it from being gced by python, that's gnarly and likely going to continue to be a relevant discovery