summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-11-04 19:02:27 -0400
committerTavian Barnes <tavianator@gmail.com>2011-11-04 19:02:27 -0400
commit3e40d9c7b75dec008beb6b4ecf71b60e8bae088d (patch)
treec6961bc743fc1a1ee909973e216313a45febcdb2 /libdimension-python
parentbdcce150b4154f84ef24b52b44801c3e735b3eb0 (diff)
downloaddimension-3e40d9c7b75dec008beb6b4ecf71b60e8bae088d.tar.xz
Let Future objects be used as context managers.
Diffstat (limited to 'libdimension-python')
-rw-r--r--libdimension-python/wrapper.pyx8
1 files changed, 8 insertions, 0 deletions
diff --git a/libdimension-python/wrapper.pyx b/libdimension-python/wrapper.pyx
index 1afb0ea..5f2b755 100644
--- a/libdimension-python/wrapper.pyx
+++ b/libdimension-python/wrapper.pyx
@@ -91,6 +91,14 @@ cdef class Future:
with nogil:
dmnsn_future_wait(self._future, progress)
+ # Let Futures be used as context managers
+ def __enter__(self):
+ return self
+ def __exit__(self, exc_type, exc_value, traceback):
+ if self._future != NULL:
+ self.join()
+ return False
+
def _assert_unfinished(self):
if self._future == NULL:
raise RuntimeError("background task finished.")