OGS
ogs_embedded_python.cpp
Go to the documentation of this file.
1
11#include "ogs_embedded_python.h"
12
13#include <pybind11/embed.h>
14
15#include "BaseLib/Logging.h"
19
28
29#ifndef OGS_BUILD_SHARED_LIBS
30
31// Hackish trick that hopefully ensures that the linker won't strip the symbol
32// pointed to by p from the library being built.
33template <typename T>
34void mark_used(T p)
35{
36 volatile T vp = p;
37 vp = vp;
38}
39
40#endif // OGS_BUILD_SHARED_LIBS
41
42namespace ApplicationsLib
43{
44pybind11::scoped_interpreter setupEmbeddedPython()
45{
46#ifndef OGS_BUILD_SHARED_LIBS
47 // pybind11_init_impl_OpenGeoSys is the function initializing the embedded
48 // OpenGeoSys Python module. The name is generated by pybind11. If it is not
49 // obvious that this symbol is actually used, the linker might remove it
50 // under certain circumstances.
51 mark_used(&pybind11_init_impl_OpenGeoSys);
52#endif
53
54 // Allows ogs to be interrupted by SIGINT, which otherwise is handled by
55 // python. See
56 // https://docs.python.org/3/c-api/exceptions.html#c.PyErr_CheckSignals and
57 // https://pybind11.readthedocs.io/en/stable/faq.html#how-can-i-properly-handle-ctrl-c-in-long-running-functions
58 constexpr bool init_signal_handlers = false;
59 return pybind11::scoped_interpreter{init_signal_handlers};
60}
61
62} // namespace ApplicationsLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
pybind11::scoped_interpreter setupEmbeddedPython()
void pythonBindSourceTerm(pybind11::module &m)
Creates Python bindings for the Python source term class.
void pythonBindBoundaryCondition(pybind11::module &m)
Creates Python bindings for the Python BC class.
void bheInflowpythonBindBoundaryCondition(pybind11::module &m)
Creates BHE Inflow Python bindings for the Python BC class.
void mark_used(T p)
PYBIND11_EMBEDDED_MODULE(OpenGeoSys, m)