Elektrine lite

← Feed

@dalke@toots.nu

Post #1978210

2026-02-20 07:24 UTC

Now my test suite says there's a file handle I forgot to close. It generates a warning to stderr. Some of my tests check stderr to ensure it's empty. I've been staring at the code, and as far as I can tell it's in a context manager which should always close it. Annoying. And the relevant code hasn't changed in months, which means it's a garbage collection timing thing where new tests changed when gc is run. I don't think I'm being happy enough. ;)

Replies (2)

  • @dalke@toots.nu 2026-02-24 14:23

    After 5 hours, found the problem. I have a function which creates a generator and returns a generator, like: def f(filename): it = g(filename) def process_it(): for value in it: yield value*2 return process_it() I needed def process_it(): try: for value in it: yield value*2 finally: it.close() I used traceback.print_stack() to help figure out if I was in a normal close() or in gc close, since it's a few levels deep.

    Open ##1978211

  • @pjacock@fediscience.org 2026-02-20 08:31

    @dalke those are a pain. Running under PyPy or Jython used to reveal a lot of those versus the assumptions with CPython.

    Open ##1978212