All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | List of all members
ucxx::python::PythonFutureTask< ReturnType, TaskArgs > Class Template Reference

User-facing bridge of C++ and Python futures. More...

#include <python_future_task.h>

Inheritance diagram for ucxx::python::PythonFutureTask< ReturnType, TaskArgs >:

Public Member Functions

 PythonFutureTask (std::packaged_task< ReturnType(TaskArgs...)> task, std::function< PyObject *(ReturnType)> pythonConvert, PyObject *asyncioEventLoop, std::launch launchPolicy=std::launch::async)
 Construct a Python future backed by C++ std::packaged_task. More...
 
 PythonFutureTask (const PythonFutureTask &)=delete
 
PythonFutureTaskoperator= (PythonFutureTask const &)=delete
 
 PythonFutureTask (PythonFutureTask &&o)=default
 The move constructor. More...
 
PythonFutureTaskoperator= (PythonFutureTask &&o)=default
 The move operator. More...
 
std::future< ReturnType > & getFuture ()
 Get the C++ future. More...
 
PyObject * getHandle ()
 Get the underlying future PyObject* handle but does not release ownership. More...
 
PyObject * release ()
 Get the underlying future PyObject* handle and release ownership. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PythonFutureTask() [1/2]

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]taskthe user-defined C++ task.
[in]pythonConvertC-Python function to convert a C object into a PyObject* representing the result of the task.
[in]asyncioEventLooppointer to a valid Python object containing the event loop that the application is using, to which the Python future will belong to.
[in]launchPolicylaunch policy for the async C++ task.

◆ PythonFutureTask() [2/2]

template<typename ReturnType , typename... TaskArgs>
ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::PythonFutureTask ( PythonFutureTask< ReturnType, TaskArgs > &&  o)
default

The move constructor.

Moves a ucxx::PythonFutureTask to the newly-constructed object.

Parameters
[in]othe object to be moved.

Member Function Documentation

◆ getFuture()

template<typename ReturnType , typename... TaskArgs>
std::future<ReturnType>& ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::getFuture ( )
inline

Get the C++ future.

Get the underlying C++ future that can be awaited and have its result read.

Returns
The underlying C++ future.

◆ getHandle()

template<typename ReturnType , typename... TaskArgs>
PyObject* ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::getHandle ( )
inline

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_errorif the object is invalid or has been already released.
Returns
The underlying PyObject* handle.

◆ operator=()

template<typename ReturnType , typename... TaskArgs>
PythonFutureTask& ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::operator= ( PythonFutureTask< ReturnType, TaskArgs > &&  o)
default

The move operator.

Moves a ucxx::PythonFutureTask to the object at the left-hand side.

Parameters
[in]othe object to be moved.

◆ release()

template<typename ReturnType , typename... TaskArgs>
PyObject* ucxx::python::PythonFutureTask< ReturnType, TaskArgs >::release ( )
inline

Get the underlying future PyObject* handle and release ownership.

Get the underlying PyObject* handle releasing ownership. This should be used when the future needs to be permanently transferred to Python code. After calling this method the object becomes invalid for any other uses.

Exceptions
std::runtime_errorif the object is invalid or has been already released.
Returns
The underlying PyObject* handle.

The documentation for this class was generated from the following file: