[Qutecsound-users] using threads via PythonQt - not really

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Qutecsound-users] using threads via PythonQt - not really

Tarmo Johannes
Hello,

I report about some experiments:

I was thinking - since PythonQt can add theoretically all the power of Qt to
CsoundQt, it would be really useful to be able to use threading possibilities
from Qt, to put any time consuming operation like database or network queries,
3D graphics, interfacing with hardware etc etc to a separate thread, let it
make its work and feed values to csound via q.setChannelValue or q.
setCsChannel and nevevr worry about dropaouts of audio between k-samples when
python or the function is too slow.

The first standalone tryout with PyQt4 (just a separate script, not under
CsoundQt) worked very well but replacing PyQt4 with PythonQt did not work out
of the box. Firts of all, PythonQt.QtCore does not have member QThread that I
was used to use for such tasks. I learned how to use QRunnable  and
QThreadPool instead.

I got it kind of working, but not really - the function in Runnable strart its
work but crashes CsoundQt on random moments with

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6b3886c in PyErr_Restore () from /usr/lib64/libpython2.7.so.1.0


Probably PythonQt does not handle the QRunnable or QThreadPool business
correctly and something in the memory get deleted or stopped too early. So I
am afraid, it is not possible to use threading this way  via PythonQt.

I attach the python script and csd I used for testing.

BUT, as result of first tests, it is possible to use QTimer as kind of
replacement for some tasks.  It means, it is possible to run a function  at a
given rate (say 1 or 10 or 100 or 1000 times in second) again and again to
mimic kind of parallel programming.


I will try to write and send an example later.

greetings,
tarmo
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users

qthread-example.csd (1K) Download Attachment
qthread-example.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

[Qutecsound-users] QTimer with pythonQt - not really

Tarmo Johannes
Hello,

I report findings from some next experiments.

I thought using QTimer in python script using PythonQt and putting some task
into some function that is called on every timer "tick" would make csd run
flawlessy and without xruns.

I was wrong. I did not know there is opcode pycallt - call a python function
when trigger is 1 (that can be used with metro opcode for example) but when I
discovered it, calling a function this way from orchestra works better than
defining am independent python interface that uses QTimer that evokes the
function.

It makes sense, if it is how Joachim suggested in a previous e-mail -  that
Csound and Python run in the same thread. I thought any Qt stuff is put into a
separate thread, but looks like it is not. So it will not make much difference.

For any case I attach two examples - one very simple about using QTimer in
python and another one a csd that reads temperature of the CPU and feeds it
into a Csound channel (works only in linux).

I feel that to do any parallel programming (like using threads to work with
some hardware or anything like that), it is better to write a different
interface in some other language and use csound API to communicate the results
to csound.

cheers!
tarmo
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users

qtimer-example1.py (1K) Download Attachment
qtimer-example2.csd (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Qutecsound-users] using threads via PythonQt - not really

Andres Cabrera
Administrator
In reply to this post by Tarmo Johannes
Hi Tarmo,

Still catching up on emails...

What you say is true, there is no QThread in QtCore for PythonQt. I
wonder why...

I think you could also try using python threads:
http://docs.python.org/2/library/threading.html

Cheers,
Andrés

On Tue, Mar 12, 2013 at 5:03 AM, Tarmo Johannes
<[hidden email]> wrote:

> Hello,
>
> I report about some experiments:
>
> I was thinking - since PythonQt can add theoretically all the power of Qt to
> CsoundQt, it would be really useful to be able to use threading possibilities
> from Qt, to put any time consuming operation like database or network queries,
> 3D graphics, interfacing with hardware etc etc to a separate thread, let it
> make its work and feed values to csound via q.setChannelValue or q.
> setCsChannel and nevevr worry about dropaouts of audio between k-samples when
> python or the function is too slow.
>
> The first standalone tryout with PyQt4 (just a separate script, not under
> CsoundQt) worked very well but replacing PyQt4 with PythonQt did not work out
> of the box. Firts of all, PythonQt.QtCore does not have member QThread that I
> was used to use for such tasks. I learned how to use QRunnable  and
> QThreadPool instead.
>
> I got it kind of working, but not really - the function in Runnable strart its
> work but crashes CsoundQt on random moments with
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff6b3886c in PyErr_Restore () from /usr/lib64/libpython2.7.so.1.0
>
>
> Probably PythonQt does not handle the QRunnable or QThreadPool business
> correctly and something in the memory get deleted or stopped too early. So I
> am afraid, it is not possible to use threading this way  via PythonQt.
>
> I attach the python script and csd I used for testing.
>
> BUT, as result of first tests, it is possible to use QTimer as kind of
> replacement for some tasks.  It means, it is possible to run a function  at a
> given rate (say 1 or 10 or 100 or 1000 times in second) again and again to
> mimic kind of parallel programming.
>
>
> I will try to write and send an example later.
>
> greetings,
> tarmo

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users