Commit 9cdde0b5 authored by Jørgen Lien Sellæg's avatar Jørgen Lien Sellæg
Browse files

working embedded example

parent 49e14571
*build*
\ No newline at end of file
*build*
*__pycache__*
\ No newline at end of file
add_definitions(-DPYTHON_PATH="/home/jorgels/src/python-meetup/pybind/embedded_example")
add_executable(embedded_example main.cpp)
target_link_libraries(embedded_example PRIVATE pybind11::embed)
\ No newline at end of file
target_link_libraries(embedded_example PRIVATE pybind11::embed)
......@@ -31,20 +31,25 @@ PYBIND11_EMBEDDED_MODULE(Api, api) {
int main() {
py::scoped_interpreter guard{};
try {
py::module::import("test");
}
catch(...) {
std::cout << "ERROR" << std::endl;
}
auto sys = py::module::import("sys");
sys.attr("path").cast<py::list>().append(PYTHON_PATH);
auto &controller = controller::get();
std::cout << "starting process" << std::endl;
std::cout << "waiting for cancel signal.";
py::module module;
int i = 0;
while(!controller.stop) {
sleep(1);
if(!module) {
module = py::module::import("stopscript");
}
if(i == 10) {
module.attr("stop")();
}
std::cout << "." << std::flush;
sleep(1);
i++;
}
}
from Api import Controller
def stop():
c = Controller()
c.stop = True
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