[Pyrex] too much work in c function
Bryan Weingarten
bryan.weingarten at pobox.com
Mon May 24 04:12:48 CEST 2004
i use mozilla thunderbird as my mail/newsreader. when i post code
using the format "text only". the line endings in my code is all
messed up when i see my own posting. so i post with the format "Rich
Text (HTML) only". now i can see my posts as i sent them, but greg
says it's all messed up in his reader. i'm now sending this with the
format "Plain and Rich (HTML) Text".
---
i'm still working on this problem where the following code is called
from a wxPython GUI. i have a test program that contains two buttons.
one button calls the play method of the following class and plays an mp3
file. the second button is brings up a simple message dialog. the
problem is the when the following play method is called and the music is
playing, you are unable to press the button to display the message
dialog. essentially, the GUI app is frozen until the play of the mp3
file is finished. i thought the PyEval_SaveThread and
PyEval_RestoreThread would work, but not only does it not work, the app
crashes when you press the button the display the message dialog. as
suggested by simon i looked at the dsptools, but i wasn't able to get
anything working with my app. following is my code with the Thread
functions added . i've tested this with the default _callback as well
as a callback from the calling python script. in both cases the app
just hangs after the music is finished playing. i'm also not able to
press the message dialog button while the play is happening. what i
was trying to accomplish is giving back control to python while the c
code is busy, but obviously this is completely wrong.
bryan
cdef extern from "Python.h":
ctypedef struct PyThreadState
PyThreadState * PyEval_SaveThread()
void PyEval_RestoreThread(PyThreadState *)
cdef PyThreadState *_thread
default_callback = eval('lambda *args: 1')
cdef class Play:
def play(self, callback=None):
global _thread
if not callback:
callback = default_callback
self.callback = callback
mpgedit_play_set_status_callback(self.ctx, _callback_wrapper,
<void*>callback)
more = True
_thread = NULL
while(more):
_thread = PyEval_SaveThread()
more = mpgedit_play_frame(self.ctx)
if _thread:
PyEval_RestoreThread(_thread)
_thread = NULL
cdef int _callback_wrapper(void *callback, long sec, long msec) except
*:
global _thread
PyEval_RestoreThread(_thread)
_thread = NULL
return (<object>callback)(sec, msec)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20040523/55782cda/attachment.html
More information about the Pyrex
mailing list