On Tue, Apr 21, 2020 at 1:39 AM Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
I don't get this whole business of channels being associated with interpreters, or why there needs to be a distinction between release() and close().
To my mind, a channel reference should be like a file descriptor for a pipe. When you've finished with it, you close() it. When the last reference to a channel is closed or garbage collected, the channel disappears. Why make it any more complicated than that?
You've mostly described what the PEP proposes: when all objects wrapping a channel in an interpreter are destroyed, that channel is automatically released. When all interpreters have released the channel then it is automatically closed. The main difference is that the PEP also provides an way to explicitly release or close a channel. Providing just "close()" would mean one interpreter could stomp on all other interpreters' use of a channel. Working around that would require clunky coordination (likely through other channels). The alternative ("release()") is much simpler.
You seem to be worried about channels getting leaked if someone forgets to close them. But it's just the same for files and pipes, and nobody seems to worry about that.
Fair enough. :) -eric