<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On May 13, 2014, at 7:50 PM, Femto Trader <<a href="mailto:femto.trader@gmail.com">femto.trader@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hello,<div><br></div><div>thanks for your reply.</div><div><br></div><div>I don't know Tornado at all.</div><div><br></div><div>I'm not a very talented developer....</div><div>Talking to me of "eventlet on pyqt" or "gevent on pyqt" looks like poetry to me ;-)</div></div></blockquote><div><br></div><div>Hah! While admitting to your own limitations is a sign of intelligence, resigning from a daunting</div><div>challenge is not a virtue.</div><div><br></div><div>It�s foreign now because you don�t know the terms, something a quick Google search would resolve.</div><div><br></div><div>PyQT uses an event loop to make multiple things happen at once, e.g. playing music while drawing the progress</div><div>bar of a file copy operation.  Your BlockingConnection is blocking this event loop so nothing can happen while you�re</div><div>reading from the RabbitMQ connection socket.</div><div><br></div><div>Every event driven network library like Twisted, Eventlet, Gevent, Tornado etc comes with a different event loop</div><div>implementation, but eventlet and gevent is special: it uses greenlets to yield control back</div><div>to the event loop so you can write normal, imperative style Python code.</div><div><br></div><div>Read about eventlet here: <a href="http://eventlet.net">http://eventlet.net</a></div><div><br></div><div>So if you can replace eventlet�s event loop with pyqt, then you can use any existing (eventlet compatible) Python code</div><div>with pyqt.  I did a quick google search and found �eventlet-pyqt�[0] that will let you do exactly this, but I don�t</div><div>know how recent this project is and there could be something better out there now.</div><div><br></div><div>In short: Using eventlet you can magically turn your BlockingConnection into a non-blocking one,</div><div>so if you can hook eventlet into pyqt you have solved your problem.</div><div><br></div><div>[0] <a href="https://code.google.com/p/eventlet-pyqt/">https://code.google.com/p/eventlet-pyqt/</a></div><div><br></div><div><br></div><br><blockquote type="cite"><div dir="ltr">

<div><br></div><div>Luke also said me something else:</div><div>"<span style="font-family:arial,sans-serif;font-size:13px">One solution that will likely work for you is to move your MQ code to a new thread, and send a signal back to the GUI thread whenever a message arrives.</span>"</div>

<div><br></div><div>Can someone from RabbitMQ dev team be in touch with PyQt / PySide dev teams</div>
<div>and also PyQtGraph devs in order to have a very basic sample example because displaying realtime</div><div>data coming from a messaging queue could be useful.</div></div></blockquote><div><br></div><div>This seems like a fringe use case and I doubt there's a big audience for such a tutorial.</div><div>Doing so using threads would be a bad practice at that, so if there was an audience</div><div>it would make more sense to invest in a proper �pika on the pyqt event loop� extension.</div><br><blockquote type="cite"><div dir="ltr"><div><br></div><div>One basic example could be:</div>

<div>one python script connect to RabbitMQ and send a random number</div><div>an other script receive data and plot them into a PyQtGraph.</div><div><br></div><div>I'm not very familiar with threading so I wonder </div>

<div>what will happen if thread that will receive data will take more time to compute data</div><div>(do some calculations on these data) than task to display them</div></div></blockquote><div><br></div><div><br></div>Python has the global interpreter lock (GIL) so you cannot perform CPU bound operations</div><div>on multiple cores unless you drop down to C and unlock the GIL.</div><div><br></div><div>It would be the same situation as when you use an Async I/O framework like eventlet/twisted/tornado</div><div>and any CPU bound operation will block the rest of the program.</div><div><br></div><div>With eventlet there is a hack to yield control back to the event loop by using</div><div>`time.sleep(0)` (eventlet monkey patches must be applied, yuo did read about eventlet already right?).</div><div>But that means you must find control points in your CPU bound operations and inject sleeps into it,</div><div>which is not exactly pretty.  Usually the solution is to use IPC and start separate OS processes for</div><div>CPU bound calculations, e.g. using Python�s multiprocessing.</div><div><br></div><div><blockquote type="cite"><div dir="ltr"><div><br></div><div><br></div><div>Femto</div><div>
<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-13 16:07 GMT+02:00 Ask Solem <span dir="ltr"><<a href="mailto:ask@rabbitmq.com" target="_blank">ask@rabbitmq.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class=""><br>
On May 13, 2014, at 2:54 PM, Michael Klishin <<a href="mailto:mklishin@gopivotal.com">mklishin@gopivotal.com</a>> wrote:<br>
<br>
>  On 12 May 2014 at 00:34:58, Femto (<a href="mailto:femto.trader@gmail.com">femto.trader@gmail.com</a>) wrote:<br>
>>> maybe you noticed Qt have an event loop<br>
>><br>
>> and I think it's doing odd things with pika.BlockingConnection<br>
>><br>
>><br>
>> Any help is welcome.<br>
><br>
> I doubt that it can, although I know nothing about Qt and little about<br>
> Pika implementation.<br>
><br>
> Have you tried using a different connect, e.g. Tornado?<br>
<br>
</div>If PyQt does indeed use an event loop then you will not be able to use a blocking connection.<br>
<br>
You have several choices:<br>
<br>
1) Implement a pika connection implementation using the PyQt event loop.<br>
2) Use a �eventlet on pyqt� or �gevent on pyqt� implementation like eventlet-pyqt<br>
    and use the eventlet or gevent connection in pika.<br>
3) Run pyqt in a separate thread.  This is only an option if pyqt actually supports it, which may<br>
    very well not be the case.<br>
<br>
</blockquote></div><br></div></div>
</blockquote></div><br></body></html>