[Pyrex] while loop not detecting ctrl-c

Bryan Weingarten bryan.weingarten at pobox.com
Wed Nov 26 01:56:39 CET 2003


greg,

i'm not sure i'm understanding what you mean by a  default callback.  i 
thought this was what you meant, but it didn't work.  i changed the 
callback parameter to default to default_play_callback function which is 
also in the pyrex module.

bryan

-----------


def default_play_callback(sec, msec):
    return 1       
       
cdef class Play:  
    cdef void   *ctx
    cdef object  callback
   
    def __new__(self, mp3file):  
        self.ctx = mpgedit_play_init(mp3file)

    def __dealloc__(self):
        mpgedit_play_close(self.ctx)

    def play(self, callback=default_play_callback):
        self.callback = callback
        if callback:
            mpgedit_play_set_status_callback(self.ctx, 
_callback_wrapper, <void*>callback)                                   
        while(mpgedit_play_frame(self.ctx)): pass           

Greg Ewing wrote:

>Bryan Weingarten <bryan.weingarten at pobox.com>:
>
>  
>
>>when Play.play() is called and a callback parameter is specified, the
>>user can do a ctrl-c (on windows) and break out of the play.  my guess
>>why this works is that the callback ends up in the python interpreter
>>and the pyrex "except *" is able to detect it with PyErr_Occurred().
>>but if callback is not specified, the while loop never goes back to
>>the python interpreter during the loop and the ctrl-c doesn't get
>>detected.
>>    
>>
>
>I'd say your guess is spot-on.
>
>You could fix this by having the extension always install a callback,
>either a user-supplied one or a default one that does nothing other
>than allow the exception to be detected.
>
>Greg Ewing, Computer Science Dept, +--------------------------------------+
>University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
>Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
>greg at cosc.canterbury.ac.nz	   +--------------------------------------+
>
>_______________________________________________
>Pyrex mailing list
>Pyrex at lists.copyleft.no
>http://lists.copyleft.no/mailman/listinfo/pyrex
>
>
>  
>





More information about the Pyrex mailing list