From: Jeff A. <ja...@fa...> - 2012-12-22 15:10:31
|
I've adapted the Closer object Philip provided in _io.fileio to apply to I/O objects in general. As before, it engages the general mechanism register/unregisterCloser() in PySystemState. The container that holds the closers, although it is a set, guarantees iteration in the order objects were added. My thought in extending use of Closer is that simply closing the file (at the handle level) on exit is not all you want: you'd like any data in a BufferedWriter to be flushed as well. And first. There's a couple of things wrong with what I'm doing at the moment, that I think would be solved by: 1. invoking the closers in reverse order of their addition; and 2. either working from a copy or disabling removal once we start iterating the list. The reverse order is what guarantees (in most circumstances) flushing the buffers before force-closing the file into which they should go. And the copy would fix the concurrent modification error that occurs when the downstream file tries to remove itself during flush-and-close propagation. Does anyone see a problem with messing with the order in this way? There can be multiple PySystemState objects. Should I think of these as distinct interpreters, or is there some chance a Python object from one of them would be in use in another at the time clean up occurs? Do PySystemState objects always hang around until JVM exit or might they clean up sooner? Jeff |