Damnit Python. Today I learnt that Python is super...
# development
Damnit Python. Today I learnt that Python is super helpful, and if you call
, 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.
How’d you discover this? Sounds like an intense story
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"
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.
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
... that's ... a really annoying API.
(the fdopen closing things its been given bit, maybe the other thing too.)
They are both… Suboptimal 🙂
But now I know 😄
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
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