diff --git a/doc/source/misc.rst b/doc/source/misc.rst index 79c63518b4bb6e5c739e27e712b195ee7b6bce73..ba86c530f9bf435cb30664f062c6f40ef5b429c4 100644 --- a/doc/source/misc.rst +++ b/doc/source/misc.rst @@ -102,6 +102,7 @@ Version 2013.1 * Add :meth:`pyopencl.array.Array.__getitem__`, supporting generic slicing. Note that many (most) operations on sliced arrays will fail for now. This will be fixed in a future release. +* :class:`pyopencl.CommandQueue` may be used as a context manager (in a ``with`` statement) Version 2012.1 -------------- diff --git a/doc/source/runtime.rst b/doc/source/runtime.rst index cc28e5616fed28bf7be78d1b86da2d13b843a537..f2b8fdbccbdc3a05f2ad3ddb00231d8bf86589f0 100644 --- a/doc/source/runtime.rst +++ b/doc/source/runtime.rst @@ -195,6 +195,15 @@ Command Queues and Events if *device* is None, one of the devices in *context* is chosen in an implementation-defined manner. + A :class:`CommandQueue` may be used as a context manager, like this:: + + with cl.CommandQueue(self.cl_context) as queue: + enqueue_stuff(queue, ...) + + .. versionadded:: 2013.1 + + Context manager capability. + .. attribute:: info Lower case versions of the :class:`command_queue_info` constants diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index c9ccf4ba06fefcbd70e0a03cb763c896c1f2fb40..11e4fc5a015b51adacc8235045bcf841e472135e 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -450,6 +450,17 @@ def _add_functionality(): # }}} + # {{{ CommandQueue + + def command_queue_enter(self): + return self + + def command_queue_exit(self, exc_type, exc_val, exc_tb): + return self + + CommandQueue.__enter__ = command_queue_enter + CommandQueue.__exit__ = command_queue_exit + # {{{ _Program (the internal, non-caching version) def program_get_build_logs(self):