Message241794
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) |
|
Date |
User |
Action |
Args |
2015-04-22 10:17:12 | mpaolini | set | recipients:
+ mpaolini, r.david.murray, docs@python, martin.panter, sjdrake |
2015-04-22 10:17:12 | mpaolini | set | messageid: <1429697832.04.0.661077443795.issue23227@psf.upfronthosting.co.za> |
2015-04-22 10:17:12 | mpaolini | link | issue23227 messages |
2015-04-22 10:17:11 | mpaolini | create | |
|