[C++-sig] Not using virtual method

Richard M Norton rmn201 at ecs.soton.ac.uk
Thu May 6 11:24:44 CEST 2004


How can i hold the interpreter for an asynchronized method calling? 
The play calls the transform method in this way, so how do i approach this?


Quoting Pierre Barbier de Reuille <pierre.barbier at cirad.fr>:

> In your callback wrapper you have to be sure, before you call any
> Python, you hold the Python Interpreter. If you do not, you're program
> will crash !
> 
> Le jeu 06/05/2004 à 05:53, bob bob a écrit :
> > 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
> > would like to try creating a thin wrapper to allow play to allow
> > threads,
> > 
> > how can you do this?
> > 
> >  
> > 
> > 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 at 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 
> -- 
> 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 
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 








More information about the Cplusplus-sig mailing list