File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments