Skip to content

Commit 4630ebf

Browse files
committed
elaborate on comment
1 parent 6ae670f commit 4630ebf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

unpythonic/net/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,19 @@ def read_more_input():
277277
# (This cannot lose data, since the source object itself has no buffer. There is
278278
# an app-level buffer in ReceiveBuffer, and the underlying socket has a buffer,
279279
# but at the level of the "source" abstraction, there is no buffer.)
280-
src.close() # PyPy recommends closing generators explicitly.
280+
#
281+
# PyPy recommends closing generators explicitly when not needed anymore,
282+
# but not exhausted, instead of leaving the instance lying around to be
283+
# picked up by the GC some time later (if ever). CPython's refcounting GC
284+
# of course picks it up immediately when the last reference goes out of scope.
285+
#
286+
# I have no idea if that piece of advice applies also when a generator exits
287+
# due to an exception. Probably not (control has escaped the body of that
288+
# generator instance permanently, right?), but closing it shouldn't hurt,
289+
# because when a generator has already exited, close() is a no-op. See:
290+
# https://amir.rachum.com/blog/2017/03/03/generator-cleanup/
291+
# https://www.python.org/dev/peps/pep-0342/
292+
src.close()
281293
src = socketsource(sock)
282294

283295
# Process the server's response to the blank line.

0 commit comments

Comments
 (0)