Marco Paolini added the comment:
I think there is an issue in the way you designed your cleanup logic. So I
think this issue is invalid.
Usually, the code (funcion, class, ...) that *opens* the file should also be
resposible of closing it.
option 1) the caller opens and closes the file and wrapping the logged lines in
a try/finally
def logged_lines(f):
try:
for line in f:
logging.warning(line.strip())
yield line
finally:
logging.warning('closing')
f = open('yyy', 'r')
try:
for l in logged_lines(f):
print(l)
finally:
f.close()
option 2) the funcion opens and closes the file
def logged_lines(fname):
f = open('yyy', 'r')
try:
for line in f:
logging.warning(line.strip())
yield line
finally:
logging.warning('closing')
f.close()
for l in logged_lines('yyy'):
print(l)
----------
nosy: +mpaolini
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23227>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com