template<typename ReturnType, typename... TaskArgs>
class ucxx::python::PythonFutureTask< ReturnType, TaskArgs >
User-facing bridge of C++ and Python futures.
User-facing bridge of C++ and Python futures, notifying the Python future handled by this object when the underlying C++ future completes.
template<typename ReturnType , typename... TaskArgs>
ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::PythonFutureTask |
( |
std::packaged_task< ReturnType(TaskArgs...)> |
task, |
|
|
std::function< PyObject *(ReturnType)> |
pythonConvert, |
|
|
PyObject * |
asyncioEventLoop, |
|
|
std::launch |
launchPolicy = std::launch::async |
|
) |
| |
|
inlineexplicit |
Construct a Python future backed by C++ std::packaged_task
.
Construct a future object that receives a user-defined C++ std::packaged_task
which runs asynchronously using an internal std::async
that ultimately notifies a Python future that can be awaited in Python code.
Note that this call will take the Python GIL and requires that the current thread have an asynchronous event loop set.
- Parameters
-
[in] | task | the user-defined C++ task. |
[in] | pythonConvert | C-Python function to convert a C object into a PyObject* representing the result of the task. |
[in] | asyncioEventLoop | pointer to a valid Python object containing the event loop that the application is using, to which the Python future will belong to. |
[in] | launchPolicy | launch policy for the async C++ task. |
template<typename ReturnType , typename... TaskArgs>
Get the underlying future PyObject*
handle but does not release ownership.
Get the underlying PyObject*
handle without releasing ownership. This can be useful for example for logging, where we want to see the address of the pointer but do not want to transfer ownership.
- Warning
- The destructor will also destroy the Python future, a pointer taken via this method will cause the object to become invalid.
- Exceptions
-
std::runtime_error | if the object is invalid or has been already released. |
- Returns
- The underlying
PyObject*
handle.