All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ucxx::python::PythonFutureTaskCollector Class Reference

A garbage-collector for Python futures. More...

#include <python_future_task_collector.h>

Public Member Functions

void push (PyObject *handle)
 
void collect ()
 
 PythonFutureTaskCollector (const PythonFutureTaskCollector &)=delete
 
PythonFutureTaskCollectoroperator= (PythonFutureTaskCollector const &)=delete
 
 PythonFutureTaskCollector (PythonFutureTaskCollector &&o)=delete
 
PythonFutureTaskCollectoroperator= (PythonFutureTaskCollector &&o)=delete
 
 ~PythonFutureTaskCollector ()
 

Static Public Member Functions

static PythonFutureTaskCollectorget ()
 

Public Attributes

std::vector< PyObject * > _toCollect {}
 Tasks to be collected.
 
std::mutex _mutex {}
 Mutex to provide safe access to _toCollect.
 

Detailed Description

A garbage-collector for Python futures.

Garbage-collects Python futures. It may be unsafe to require the GIL during ucxx::PythonFutureTask since the exact time the destructor is called may be unpredictable w.r.t. the Python application, and thus requiring the GIL may result in deadlocks if it can't be done at appropriate stages. The application is thus responsible to ensure PythonFutureTaskCollector::push() is regularly called and ultimately responsible for cleaning up before terminating, otherwise a resource leakage may occur.

Constructor & Destructor Documentation

◆ ~PythonFutureTaskCollector()

ucxx::python::PythonFutureTaskCollector::~PythonFutureTaskCollector ( )

Destructor.

Destructor of the collector. Warns if any tasks were pushed but not collected.

Member Function Documentation

◆ collect()

void ucxx::python::PythonFutureTaskCollector::collect ( )

Decrement each reference previously pushed exactly once.

Decrement each reference (i.e., garbage collect) that was previously pushed via the push() method exactly once, cleaning internal references at the end.

WARNING: Calling this method will attempt to take the GIL, so make sure no other thread currently owns it while this thread also competes for other resources that the Python thread holding the GIL may require as it may cause a deadlock.

◆ get()

static PythonFutureTaskCollector& ucxx::python::PythonFutureTaskCollector::get ( )
static

Get reference to PythonFutureTaskCollector instance.

PythonFutureTaskCollector is a singleton and thus must not be directly instantiated. Instead, users should call this static method to get a reference to its instance.

◆ push()

void ucxx::python::PythonFutureTaskCollector::push ( PyObject *  handle)

Push a Python handle to be later collected.

Push a Python handle to be later collected. This method does not require the GIL.


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