Skip to contentSkip to conversation

pyalsa with threads allowed for python (Py_BEGIN_ALLOW_THREADS & Py_END_ALLOW_THREADS)

DISCUSSION ki.ber.kom.uni.st 2 participants 2 messages May 17, 2008 – May 19, 2008

lore
Share & tools
lore
#0 lore raw

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...

#1 lore raw
Quoted 6 lines · ki.ber.kom.uni.st

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;

Added to our repository. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.