Hello, Im having difficulties concerning using callbacks that have been extended in python. Im using the windows video API DirectShow to play video to a screen through a transform method. The problem occurs when the Transform method is called from an object extended in python as a callback, not when called explicitly. How do I represent this functionality and prevent the python interpreter from crashing? I do not think the problem in this case is from the live times of the objects, but I may be wrong. Is using boosts function and bind features a solution, and if so how? Many Thanks, Richard // Cut down version of the C++ code class Callback { virtual void Transform() = 0; } class Player { Player(Callback *); void Play(); // Play the video to the screen, returns allowing video to continue play } class Callback_Wrap : public Callback { Callback_Wrap(PyObject *obj) : self(obj) {} virtual Transform() {call_method<void>(self, Transform);} PyObject *self; } BOOST_PYTHON_MODULE(MyVideo) { class_<Callback, boost::noncopyable, boost::shared_ptr<Callback_Wrap> >(Callback) .def(Transform, &Callback::Transform) ; class_<Player>(Player, init<Calback *>()) .def(Play, &Player::Play) ; } # Example python use from MyVideo import * class My_Callback(Callback): def Transform(self): print Hello, My_Callback here! a = My_Callback() b = Player(a) a.Play()
Is your video playing in another thread ? If that's the case, that's very probably a problem with the "thread-safety" of Python. If you successfully overcome this problem please tell the list, I'm very interested in that ! Briefly the problem is that the thread executing some Python code has to acquire the interpreter lock. But you can't check the lock without blocking your thread ... (at least I found no function to do that in the Python/C interface). Pierre On Fri, 2004-04-30 at 15:25, Richard M Norton wrote:
Hello, Im having difficulties concerning using callbacks that have been extended in python. Im using the windows video API DirectShow to play video to a screen through a transform method. The problem occurs when the Transform method is called from an object extended in python as a callback, not when called explicitly. How do I represent this functionality and prevent the python interpreter from crashing? I do not think the problem in this case is from the live times of the objects, but I may be wrong. Is using boosts function and bind features a solution, and if so how?
Many Thanks, Richard
// Cut down version of the C++ code
class Callback { virtual void Transform() = 0; }
class Player { Player(Callback *); void Play(); // Play the video to the screen, returns allowing video to continue play }
class Callback_Wrap : public Callback { Callback_Wrap(PyObject *obj) : self(obj) {} virtual Transform() {call_method<void>(self, Transform);} PyObject *self; }
BOOST_PYTHON_MODULE(MyVideo) { class_<Callback, boost::noncopyable, boost::shared_ptr<Callback_Wrap> >(Callback) .def(Transform, &Callback::Transform) ;
class_<Player>(Player, init<Calback *>()) .def(Play, &Player::Play) ; }
# Example python use
from MyVideo import *
class My_Callback(Callback): def Transform(self): print Hello, My_Callback here!
a = My_Callback() b = Player(a) a.Play()
_______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
participants (2)
-
Pierre Barbier de Reuille -
Richard M Norton