Henrique Andrade <h...@unscrambl.com> added the comment: Your comparison is not correct.
RAII in C++ ensures that, on object destruction, resources that have been acquired will be closed and deallocated. The closest analogy in Python is the use of a context manager, which, btw, a Queue does not provide. Indeed, such a design (with a context manager) would have been cleaner because, on exit, both pipes would have been closed and file descriptors would not hang around. And, yes, that is what I'd prefer too - but one can't have everything. :) With the current design, which is more akin to Java, one is exposed to the vagaries of the garbage collector. Note that, even in Java, try-with-resources and the auto-closeable interface would also take care of this. In fact, most the Java classes that require external resources have migrated to this model. For these reasons, I think the design could be substantially improved (i.e., with a context manager or with the provision of a method that really terminates the queue, so resources are properly closed immediately). On Sun, Mar 18, 2018 at 1:12 PM, Pablo Galindo Salgado < rep...@bugs.python.org> wrote: > > Pablo Galindo Salgado <pablog...@gmail.com> added the comment: > > >"I want to terminate the queue and make sure that no resources are leaked. > > Then you don't need to do anything special, those will be cleared on > object destruction. This is not an unusual pattern even in other languages. > For example, RAII in C++ is one of the most used patterns for acquiring > resources and that works cleaning those resources on object destruction. > > ---------- > > _______________________________________ > Python tracker <rep...@bugs.python.org> > <https://bugs.python.org/issue33081> > _______________________________________ > -- Henrique Andrade | +1-530-426-2123 | h...@unscrambl.com | https://unscrambl.com ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33081> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com