[alsa-devel] pyalsa with threads allowed for python (Py_BEGIN_ALLOW_THREADS & Py_END_ALLOW_THREADS)

ki.ber.kom.uni.st ki.ber at kom.uni.st
Sat May 17 18:40:04 CEST 2008


i develop my app iterating ipython interactive sessions with pasting
the good code into files (which eventually being loaded back to
ipython sessions)...

for that kind of development i need pyalsa to run in python threads...
when i did (as it is now) alsaseq.Sequencer.receive_events(100) in
infinite loop of pyqt4 thread it always steal interaction from ipython
and it makes interaction unusable... it gets back every now and then
almost randomly and definitively not frequent enough to be usable..
hope this description explained enough of what's happening...

the solution was to make time.sleep(.001) at the end of while True:
loop... it took me several hours to find out the solution... i was
quite happy with the solution but my guru friends told me that's dirty
and i'm lame...

the other solution is in particular case of receive_events to put
Py_*_ALLOW_THREADS

    Py_BEGIN_ALLOW_THREADS;
    ret = poll(self->receive_fds, self->receive_max, timeout);
    Py_END_ALLOW_THREADS;

around poll...

this url should explain this strange phenomena (to me) to the real
programmers: http://www.python.org/doc/1.5.2/api/threads.html

in my case my programming guru akapav sort it out after couple of
minuts checking the code...

hope this is of some interest to pyalsa devs... i definitively would
need most of the functions being ready to run in threads....

thanx.. keep up the good work...


More information about the Alsa-devel mailing list