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 | |
PythonFutureTaskCollector & | operator= (PythonFutureTaskCollector const &)=delete |
PythonFutureTaskCollector (PythonFutureTaskCollector &&o)=delete | |
PythonFutureTaskCollector & | operator= (PythonFutureTaskCollector &&o)=delete |
~PythonFutureTaskCollector () | |
Static Public Member Functions | |
static PythonFutureTaskCollector & | get () |
Public Attributes | |
std::vector< PyObject * > | _toCollect {} |
Tasks to be collected. | |
std::mutex | _mutex {} |
Mutex to provide safe access to _toCollect . | |
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.
ucxx::python::PythonFutureTaskCollector::~PythonFutureTaskCollector | ( | ) |
Destructor.
Destructor of the collector. Warns if any tasks were pushed but not collected.
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.
|
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.
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.