summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-08-19 00:05:22 -0600
committerTavian Barnes <tavianator@gmail.com>2011-08-19 00:05:22 -0600
commitc0284b69fe0ee82d1f604a1b6f0511b4f129b919 (patch)
tree921fd2dc329cbf01383cc3cdd4e30e6954318775 /libdimension-python
parent8ba39e9ea0ccfb08edaa9179e4893acb6c478aad (diff)
downloaddimension-c0284b69fe0ee82d1f604a1b6f0511b4f129b919.tar.xz
Support thread cancelation, and handle ^C in the client.
Diffstat (limited to 'libdimension-python')
-rw-r--r--libdimension-python/dimension.pxd1
-rw-r--r--libdimension-python/dimension.pyx12
2 files changed, 10 insertions, 3 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd
index 5523cc0..a3523d0 100644
--- a/libdimension-python/dimension.pxd
+++ b/libdimension-python/dimension.pxd
@@ -71,6 +71,7 @@ cdef extern from "../libdimension/dimension.h":
ctypedef struct dmnsn_progress
int dmnsn_finish_progress(dmnsn_progress *progress)
+ void dmnsn_cancel_progress(dmnsn_progress *progress)
double dmnsn_get_progress(dmnsn_progress *progress)
void dmnsn_wait_progress(dmnsn_progress *progress, double prog)
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 673dc50..0c0c214 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -60,15 +60,21 @@ cdef class Progress:
finally:
self._progress = NULL
+ def cancel(self):
+ self._assert_unfinished()
+ dmnsn_cancel_progress(self._progress)
+
def progress(self):
- if self._progress == NULL:
- raise RuntimeError("background task finished.")
+ self._assert_unfinished()
return dmnsn_get_progress(self._progress)
def wait(self, progress):
+ self._assert_unfinished()
+ dmnsn_wait_progress(self._progress, progress)
+
+ def _assert_unfinished(self):
if self._progress == NULL:
raise RuntimeError("background task finished.")
- dmnsn_wait_progress(self._progress, progress)
cdef _Progress(dmnsn_progress *progress):
cdef Progress self = Progress.__new__(Progress)