summaryrefslogtreecommitdiffstats
path: root/libdimension-python/dimension.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension-python/dimension.pyx')
-rw-r--r--libdimension-python/dimension.pyx12
1 files changed, 11 insertions, 1 deletions
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 601fb69..0fed65f 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -42,9 +42,11 @@ def terminal_width():
cdef class Progress:
cdef dmnsn_progress *_progress
+ cdef _finalizer
def __cinit__(self):
self._progress = NULL
+ self._finalizer = None
def __init__(self):
raise RuntimeError("attempt to create a Progress object.")
@@ -58,6 +60,8 @@ cdef class Progress:
try:
if dmnsn_finish_progress(self._progress) != 0:
raise RuntimeError("background task failed.")
+ if self._finalizer is not None:
+ self._finalizer()
finally:
self._progress = NULL
@@ -554,7 +558,13 @@ cdef class Canvas:
if file == NULL:
raise OSError(errno, os.strerror(errno))
- return _Progress(dmnsn_png_write_canvas_async(self._canvas, file))
+ def finalize():
+ if fclose(file) != 0:
+ raise OSError(errno, os.strerror(errno))
+
+ progress = _Progress(dmnsn_png_write_canvas_async(self._canvas, file))
+ progress._finalizer = finalize
+ return progress
def draw_GL(self):
"""Export the canvas to the current OpenGL context."""