Threads for javierhonduco

  1. 2

    Slightly specific to the languages I usually use, but:

    • In Python I like to use the -i flag (or the PYTHONINSPECT environment variable), which starts interactive mode when an exception is raised.

    • For bash, set -x for n00bs like myself is a must! This prints the current line being executed.

    • When I am dealing with compiled code, usually C++ or C, gdb has been a real life saver, especially setting breakpoints when some condition is true, such as when some parameter to a system call matches some particular value.

    • Nowadays for native executables, I am finding myself using bpftrace quite often, in some cases instrumenting several functions that I am interested in, either in userspace or the kernel. This has been great from a troubleshooting (fancy, not code modifications needed[1] printf debugging), performance debugging (i.e. latency of a function), and education points of view (which code paths are ran?)! I have sparingly used XRay but it’s very neat as well!

    Hope this is somewhat useful! :)

    [1]: While you are not required to recompile / re-run your code the code does indeed change, as it is patched at runtime.

    1. 3

      I wish that Python teaching materials would teach the with statement, which has been with us since Python 2.5 over a decade ago, for context management. Context managers are easily the best way to ensure that file handles are cleaned up. Everything works even on PyPy or Jython, although the PyPy documentation does not say it explicitly.

      I find the comparison to Rust interesting. The author says:

      Rust is the only popular language that models [file-descriptor management] right, reducing the chances of messing up.

      I wonder to what degree a higher-level API would have removed the problem entirely. In Monte, file descriptors cannot be accessed at all, which might have prevented the problem, but all I/O is asynchronous, which might have exacerbated the problem.

      1. 1

        Completely agree with regards to context managers, they are a very elegant!

        In Monte, file descriptors cannot be accessed at all, which might have prevented the problem

        I’m not familiar with Monte but not exposing the backing fd is a good solution to the problem. If we can’t call close(2) on arbitrary file descriptors and the file object implementation does not expose the backing fd we should be good. The main issue is that Python’s API can’t change at this point, and some low-level APIs require file descriptors to be passed around, and Python semantics can’t capture this in way that misuses are prevented.

        I brought up Rust because I really like that Rust solves it very elegantly through not having a close wrapper in the standard library, the way ownership works, and the fact that crates that wrap close(2) have this function as unsafe.