Skip to content

Commit e6a3fec

Browse files
committed
Handle GeneratorExit
1 parent 7e14f38 commit e6a3fec

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

thumbnailflow/thumbnails.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ def generate_file_thumbs(folder, preserve=False):
8989
except GeneratorExit:
9090
# the new file can't be complete: Do not write.
9191
dirty = False
92-
if preserve:
93-
if dirty:
94-
fp.write(']')
95-
fp.close()
96-
os.replace(new_thumbs_file, old_thumbs_file)
97-
else:
98-
fp.seek(0)
99-
fp.truncate()
100-
fp.close()
101-
os.remove(new_thumbs_file)
92+
# nobody wants the rest of the data
93+
return
94+
finally:
95+
if preserve:
96+
if dirty:
97+
fp.write(']')
98+
fp.close()
99+
os.replace(new_thumbs_file, old_thumbs_file)
100+
else:
101+
fp.seek(0)
102+
fp.truncate()
103+
fp.close()
104+
os.remove(new_thumbs_file)
102105
yield ']'
103106

104107
def make_file_thumbs(folder):

0 commit comments

Comments
 (0)