Boost python level with threads

It seems that boost :: python and boost :: thread are not very similar to each other, what can I say.

Refer to http://pastebin.com/Cy123mJK

This is a simplification of the problems that I encounter in my boost :: python and boost :: thread application.

If someone tells me why these problems occur; I have no idea, as I am strictly making sure that the python interaction is executed with one thread at once.

At some point, the program crashes with segfault for no apparent reason. Also, it's impossible to catch this glitch, it seems ...

Help rate!

+3
source share
1 answer

You are running python in multiple threads at the same time in Producer::run()and Consumer::run().

, :

boost::python::object writer = this->k->Get<boost::python::object>("write");

, , Boost PyObject_GetItem, boost::python::object::operator[](const std::string&) Keeper::Get. Get-call , :

{
  boost::mutex::scoped_lock l(this->k->python_keeper);
  boost::python::object writer = this->k->Get<boost::python::object>("write");
  writer(boost::python::str(os.str()));
}

: Py_Finalize(). , , boost.python .

+6

Source: https://habr.com/ru/post/1785288/


All Articles