[C++-sig] bosst.python Event object wrapped with bp::object()
Joseph Lisee
jlisee at gmail.com
Wed Feb 27 23:22:51 CET 2008
Alexander Eisenhuth <newsuser <at> stacom-software.de> writes:
> ThreadClass::threadLoop()
> {
> ...
> if (methodeCalled) {
> ...
> this->myEvent.attr("set")();
> }
>
> }
You can't do this. The Python C API (and therefore Boost.Python's) is not
thread safe. If threadloop is running in another thread along side the one the
Python interpreter is running in, accessing a Python object at the same time
will result in a crash.
You should wrap a C++ class, which has a set member that can be accessed from
Python. That way in C++ you can do: "this->myEvent.set();" Then later in
python you can access the value.
-Joe
More information about the Cplusplus-sig
mailing list