2021-01-17 01:56:27 -05:00
|
|
|
/*
|
|
|
|
|
* PythonInterface.h
|
|
|
|
|
*
|
|
|
|
|
* Created on: Jan. 14, 2021
|
|
|
|
|
* Author: mathieu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef CORELIB_SRC_PYTHON_PYTHONINTERFACE_H_
|
|
|
|
|
#define CORELIB_SRC_PYTHON_PYTHONINTERFACE_H_
|
|
|
|
|
|
2025-07-13 04:15:03 -07:00
|
|
|
#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
|
2021-01-17 01:56:27 -05:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <rtabmap/utilite/UMutex.h>
|
2023-09-17 01:19:59 -07:00
|
|
|
|
|
|
|
|
namespace pybind11 {
|
|
|
|
|
class scoped_interpreter;
|
|
|
|
|
class gil_scoped_release;
|
|
|
|
|
}
|
2021-01-17 01:56:27 -05:00
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
2023-09-17 01:19:59 -07:00
|
|
|
/**
|
2026-08-06 13:32:20 -07:00
|
|
|
* Process-wide singleton owning the embedded Python interpreter.
|
|
|
|
|
* Call PythonInterface::instance() from the main thread (typically near
|
|
|
|
|
* the top of main()) before any Python-using class is constructed.
|
2023-09-17 01:19:59 -07:00
|
|
|
*/
|
2025-07-13 04:15:03 -07:00
|
|
|
class RTABMAP_CORE_EXPORT PythonInterface
|
2021-01-17 01:56:27 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2026-08-06 13:32:20 -07:00
|
|
|
// Pass a caller tag (e.g. class name) so the main-thread assertion
|
|
|
|
|
// can report who triggered the first construction.
|
|
|
|
|
static PythonInterface & instance(const std::string & caller = "");
|
|
|
|
|
|
|
|
|
|
PythonInterface(const PythonInterface &) = delete;
|
|
|
|
|
PythonInterface & operator=(const PythonInterface &) = delete;
|
2021-01-17 01:56:27 -05:00
|
|
|
|
|
|
|
|
private:
|
2026-08-06 13:32:20 -07:00
|
|
|
explicit PythonInterface(const std::string & caller);
|
|
|
|
|
~PythonInterface();
|
|
|
|
|
|
2023-09-17 01:19:59 -07:00
|
|
|
pybind11::scoped_interpreter* guard_;
|
|
|
|
|
pybind11::gil_scoped_release* release_;
|
2021-01-17 01:56:27 -05:00
|
|
|
};
|
|
|
|
|
|
2025-07-13 04:15:03 -07:00
|
|
|
std::string RTABMAP_CORE_EXPORT getPythonTraceback();
|
2023-09-17 01:19:59 -07:00
|
|
|
|
2021-01-17 01:56:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* CORELIB_SRC_PYTHON_PYTHONINTERFACE_H_ */
|