Commit 49e14571 authored by Jørgen Lien Sellæg's avatar Jørgen Lien Sellæg
Browse files

embeded example

parent 2952ea70
add_executable(embedded_example main.cpp)
target_link_libraries(embedded_example PRIVATE pybind11::embed)
\ No newline at end of file
#include <iostream>
#include <pybind11/embed.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
class controller {
private:
controller() {}
public:
static controller &get() {
static controller c;
return c;
}
bool stop = false;
static void init_module(py::module &api) {
py::class_<controller, std::unique_ptr<controller, py::nodelete>>(api, "Controller")
.def(py::init([]() { return &(get()); }))
.def_readwrite("stop", &controller::stop)
;
}
};
PYBIND11_EMBEDDED_MODULE(Api, api) {
controller::init_module(api);
}
int main() {
py::scoped_interpreter guard{};
try {
py::module::import("test");
}
catch(...) {
std::cout << "ERROR" << std::endl;
}
auto &controller = controller::get();
std::cout << "starting process" << std::endl;
std::cout << "waiting for cancel signal.";
while(!controller.stop) {
sleep(1);
std::cout << "." << std::flush;
}
}
from sys import path
path.append("./../../build")
from time import sleep
sleep(5)
print(c)
from Api import Controller
c = controller()
c.stop = True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment