[PySide] Signal emitted on a worker thread not being received by main thread
William Dias
william.dias at gmail.com
Thu Apr 25 20:00:04 CEST 2013
I think I solved the problem by switching the order of some commands. First
I move my object to the thread and then I do all the signal/slot
connections. This way, the PySide is able to user the proper connection to
handle communication across threads.
I did some tests here and everything worked fine.
2013/4/9 Algis Kabaila <akabaila at pcug.org.au>
> **
>
> William,
>
>
>
> It may bee worth while to read about QTimer [QtCore]( Mark Summerfield's
> "Rapid GUI Porgramming with Python and Qt", pp. 373, 376. Also QTime
> [QtCore] and
>
> [QTimeEdit [QTGui] p 576. I vaguely recall that there was discussion why
> he used QTimer of Qt library rather than the simpler "sleep" of Python.
>
> Just a shot in the dark - it might be just what is needed. Worth a try, I
> think.
>
>
>
> Al.
>
>
>
>
>
> On Monday 08 April 2013 23:32:45 William Dias wrote:
>
> Lucas,
>
>
> Yes, I could, but the question is: why this is not working properly with
> qt libraries only? Why the slot is not being called? The weird thing is
> that the issue just occurs occasionally. In the last battery of tests I
> ran, I've got 149 threads created and only 2 of them didn't make the call
> to the slot.
>
>
>
> 2013/4/8 Lucas Tanure <ltanure at gmail.com>
>
> Could you use the queue in python ? with Queue.get([block[, timeout]]) ?
>
>
> Lucas A. Tanure Alves
> +55 (19) 88176559
>
>
>
> On Mon, Apr 8, 2013 at 6:59 PM, William Dias <william.dias at gmail.com>
> wrote:
>
> Hi, Tibold. Thanks for your reply.
>
>
> If I first move my worker to the new thread and then make the connection
> should it work?
>
>
> According to the documentation, it would use an auto-connection and since
> emitter and receiver don't have the same thread affinity, it would create a
> queued connection. Is it right?
>
>
> Best,
>
>
>
> 2013/4/8 Tibold Kandrai <kandraitibold at gmail.com>
>
> Hi,
>
>
>
> I think you’ll have to use queued connection when you connect the
> photoStatus signal to the photoStatus slot.
>
>
>
> See:
>
>
> http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads
>
>
>
> Cheers,
>
> Tibold
>
>
>
> From: pyside-bounces+kandraitibold=gmail.com at qt-project.org [mailto:
> pyside-bounces+kandraitibold=gmail.com at qt-project.org] On Behalf Of William
> Dias
> Sent: 2013 April 08, Monday 17:01
> To: pyside at qt-project.org
> Subject: [PySide] Signal emitted on a worker thread not being received by
> main thread
>
>
>
> Hi,
>
>
>
> I am facing an intermittent problem with my PySide application. I have a
> GUI that spawns several threads that are responsible for sending photos to
> a web server. The threads are created as shown bellow:
>
>
>
> photoConnectionThread = QThread()
>
> photoConnectionObject = http_connection.PhotoConnection(self.filename)
>
> photoConnectionObject.photoStatus.connect(self.photoStatus)
>
> photoConnectionObject.moveToThread(photoConnectionThread)
>
> photoConnectionThread.started.connect(photoConnectionObject.work)
>
> photoConnectionThread.finished.connect(self.threadFinished)
>
> photoConnectionThread.start()
>
>
>
> My worker thread tries to upload a photo only once and then emits a signal
> to the main thread so that the status can be updated in a database.
>
>
>
> def work(self):
>
> logger.info("photo object created on thread " +
> str(self.thread()))
>
> status = sendPhoto(self.filename)
>
> self.photoStatus.emit(self.filename, status)
>
> QThread.sleep(5)
>
> logger.info("exiting thread " +
> str(self.thread()))
>
> self.thread().exit(0)
>
>
>
> The problem is that, sporadically, the main thread does not receive the
> signal and consequently doesn't get the status updated.
>
>
>
> Does anybody have any idea why this is happening?
>
>
>
> I am using:
>
> Python 2.7
>
> PySide 1.1.1
>
> Windows 7
>
>
>
> Thank you!
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130425/06dd404e/attachment.html>
More information about the PySide
mailing list