[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Multithreaded Update of the QStandardItemModel Data
From: Christian Schulze <c.schulze () tlk-thermo ! com>
Date: 2018-03-12 22:35:44
Message-ID: FRXPR01MB0072796866C25A51FEBACA61D1D30 () FRXPR01MB0072 ! DEUPRD01 ! PROD ! OUTLOOK ! DE
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
[Attachment #4 (text/plain)]
Great! The issues are fixed! Thanks!
The updated example is attached. I'll try implement it in my code.
Christian
Von: Barry [mailto:barry@barrys-emacs.org]
Gesendet: Montag, 12. März 2018 23:03
An: Christian Schulze <c.schulze@tlk-thermo.com>
Cc: Florian Bruhin <me@the-compiler.org>; pyqt@riverbankcomputing.com
Betreff: Re: [PyQt] Multithreaded Update of the QStandardItemModel Data
The trick you need is that you can send a signal from a non-main thread to the gui \
main-thread.
In response to the signal you update the model. Put all the information that you need \
as the signal arg or args.
I use this idea in scm-workbench to sync the ui to background changes.
Barry
On 12 Mar 2018, at 21:52, Christian Schulze \
<c.schulze@tlk-thermo.com<mailto:c.schulze@tlk-thermo.com>> wrote: Hi Florian,
I need to update many items continuously. Several rows are updated at least once per \
second. For some use cases I have 20000 rows in total. I prepared all the data \
(new/modified/removed items), so that hardly any calculation is done in the main \
thread.
However, the main thead seems to be blocked for too long. The GUI seems to freeze for \
a short moment when I update the data. This is really annoying when you're working \
with the application and I'd like to fix that.
I had expected that I'm allowed to modify the item model, since the GUI thread only \
reads data. I don't care if an intermediate state is displayed.
So I need to implement my own threadsafe item model? Is any python based item model \
implementation threadsafe due to the GIL? Is the interaction of python and C++ fast \
enough to do this?
Thanks,
Christian
Von: Florian Bruhin [mailto:me@the-compiler.org]
Gesendet: Montag, 12. März 2018 22:13
An: Christian Schulze <c.schulze@tlk-thermo.com<mailto:c.schulze@tlk-thermo.com>>
Cc: pyqt@riverbankcomputing.com<mailto:pyqt@riverbankcomputing.com>
Betreff: Re: [PyQt] Multithreaded Update of the QStandardItemModel Data
Hi,
On Mon, Mar 12, 2018 at 08:59:11PM +0000, Christian Schulze wrote:
> I'm trying to update the QStandardItemModel data from another thread. This causes \
> several issues:
> [...]
QStandardItemModel is part of QtGui, and stuff in QtGui is not
threadsafe and must be used from the main (GUI) thread only.
> It would be great if someone could tell me how to fix this!
Your only option is pretty much "don't do this". Why do you need to
modify a QStandardItemModel from a non-main thread?
Florian
--
https://www.qutebrowser.org | me@the-compiler.org<mailto:me@the-compiler.org> \
(Mail/XMPP) GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com<mailto:PyQt@riverbankcomputing.com>
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[Attachment #5 (text/html)]
<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.E-MailFormatvorlage18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.E-MailFormatvorlage19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.E-MailFormatvorlage20
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.E-MailFormatvorlage21
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Great! \
The issues are fixed! Thanks!<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">The \
updated example is attached. I'll try implement it in my code.<o:p></o:p></span></p> \
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Christian<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif">Von:</span></b><span \
lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> \
Barry [mailto:barry@barrys-emacs.org] <br>
<b>Gesendet:</b> Montag, 12. März 2018 23:03<br>
<b>An:</b> Christian Schulze <c.schulze@tlk-therm</span><span \
style="font-size:11.0pt;font-family:"Calibri",sans-serif">o.com><br> \
<b>Cc:</b> Florian Bruhin <me@the-compiler.org>; \
pyqt@riverbankcomputing.com<br> <b>Betreff:</b> Re: [PyQt] Multithreaded Update of \
the QStandardItemModel Data<o:p></o:p></span></p> </div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">The trick you need is that you can send a signal from a non-main \
thread to the gui main-thread.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In response to the signal you update the model. Put all the \
information that you need as the signal arg or args.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I use this idea in scm-workbench to sync the ui to background \
changes.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Barry<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
On 12 Mar 2018, at 21:52, Christian Schulze <<a \
href="mailto:c.schulze@tlk-thermo.com">c.schulze@tlk-thermo.com</a>> \
wrote:<o:p></o:p></p> </div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Hi \
Florian,</span><o:p></o:p></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I \
need to update many items continuously. Several rows are updated at least once per \
second. For some use cases I have 20000 rows in total. I prepared all the data \
(new/modified/removed items), so that hardly any calculation is done in the main \
thread.</span><o:p></o:p></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">However, \
the main thead seems to be blocked for too long. The GUI seems to freeze for a short \
moment when I update the data. This is really annoying when you're working with the \
application and I'd like to fix that.</span><o:p></o:p></p> <p \
class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I \
had expected that I'm allowed to modify the item model, since the GUI thread only \
reads data. I don't care if an intermediate state is \
displayed.</span><o:p></o:p></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">So \
I need to implement my own threadsafe item model? Is any python based item model \
implementation threadsafe due to the GIL? Is the interaction of python and \
C++ fast enough to do this?</span><o:p></o:p></p> <p class="MsoNormal"><span \
lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Christian</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" \
style="font-size:11.0pt;font-family:"Calibri",sans-serif">Von:</span></b><span \
lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> \
Florian Bruhin [<a href="mailto:me@the-compiler.org">mailto:me@the-compiler.org</a>] \
<br> <b>Gesendet:</b> Montag, 12. März 2018 22:13<br>
<b>An:</b> Christian Schulze <<a \
href="mailto:c.schulze@tlk-thermo.com">c.schulze@tlk-thermo.com</a>><br> \
<b>Cc:</b> <a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a><br>
<b>Betreff:</b> Re: [PyQt] Multithreaded Update of the QStandardItemModel \
Data</span><o:p></o:p></p> </div>
</div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">Hi,</span><span lang="EN-US"> \
</span><o:p></o:p></p> <p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">On Mon, Mar 12, 2018 at 08:59:11PM \
+0000, Christian Schulze wrote:</span><span lang="EN-US"> <br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">> I'm \
trying to update the QStandardItemModel data from another thread. This causes several \
issues:</span><span lang="EN-US"> <br>
</span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">></span><span lang="EN-US"> \
<br> </span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">> [...]</span><span \
lang="EN-US"> </span><o:p></o:p></p>
<p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">QStandardItemModel is part of \
QtGui, and stuff in QtGui is not</span><span lang="EN-US"> <br>
</span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">threadsafe and must be used from \
the main (GUI) thread only.</span><span lang="EN-US"> </span><o:p></o:p></p>
<p><span lang="EN-US" style="font-family:"Calibri",sans-serif">> It \
would be great if someone could tell me how to fix this!</span><span lang="EN-US"> \
</span><o:p></o:p></p> <p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">Your only option is pretty much \
"don't do this". Why do you need to</span><span lang="EN-US"> <br>
</span><span lang="EN-US" style="font-family:"Calibri",sans-serif">modify a \
QStandardItemModel from a non-main thread?</span><span lang="EN-US"> \
</span><o:p></o:p></p> <p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">Florian</span><span lang="EN-US"> \
</span><o:p></o:p></p> <p><span lang="EN-US" \
style="font-family:"Calibri",sans-serif">-- </span><span lang="EN-US"><br> \
</span><span style="font-family:"Calibri",sans-serif"><a \
href="https://www.qutebrowser.org"><span \
lang="EN-US">https://www.qutebrowser.org</span></a></span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif"> | </span><span \
style="font-family:"Calibri",sans-serif"><a \
href="mailto:me@the-compiler.org"><span \
lang="EN-US">me@the-compiler.org</span></a></span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif"> (Mail/XMPP)</span><span \
lang="EN-US"> <br>
</span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif"> GPG: 916E B0C8 FD55 \
A072 | </span><span style="font-family:"Calibri",sans-serif"><a \
href="https://the-compiler.org/pubkey.asc"><span \
lang="EN-US">https://the-compiler.org/pubkey.asc</span></a></span><span lang="EN-US"> \
<br> </span><span lang="EN-US" \
style="font-family:"Calibri",sans-serif"> \
I love long mails! </span><span style="font-family:"Calibri",sans-serif">| \
<a href="https://email.is-not-s.ms/"> https://email.is-not-s.ms/</a></span> \
<o:p></o:p></p> </div>
</blockquote>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">_______________________________________________<br>
PyQt mailing list <a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br> <a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><o:p></o:p></p>
</div>
</blockquote>
</div>
</body>
</html>
["MultithreadedItemModelUpdate2.py" (application/octet-stream)]
[Attachment #7 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic