[Interest] QThreadPool functionality for QThreads
Frank Rueter | OHUfx
frank at ohufx.com
Wed Jan 18 08:17:41 CET 2017
thanks for your quick reply. I will try and give some more context:
I use the python requests module inside my PySide app to post requests
to a website. Some of those requests return a lot of data that I need to
parse to be able to show progress, other requests are file downloads
that I need progress bars for as they stream onto disk.
I had tried to not use threads and use QApplication.processEvents() for
each data chunk downloaded, but that made the download about 4-5 times
slower. Introducing threading made a huge difference.
My app can download a list of files at the same time. Depending on the
situation and the user request, the list of files to be downloaded can
happen asynchronously, in other situations they need to be downloaded
one after the other.
>>All I can tell you is that you don't need to do what you're trying to
do, since you don't need threads in the first place.
If I can avoid threads to do the above I would be more than happy to
adjust and get rid of them again, but I haven't managed to find a
non-threaded approach that doesn't slow down the download significantly.
On 18/01/17 6:26 PM, Thiago Macieira wrote:
> On quarta-feira, 18 de janeiro de 2017 17:21:46 PST Frank Rueter | OHUfx
>> I got another threading question for the pros out there:
>> In my current application I am using QThread objects and
>> QObject.moveToThread() to enable my GUI to download multiple files while
>> updating progress bars in the main event loop. This is the respective
> As usual, the usual disclaimer: you do not need threads to do networking or
> file I/O. The combined overhead of the networking I/O and saving of the files is
> unlikely to overwhelm the event loop to the point that the progress bar can't
> update smoothly.
> I'm not saying impossible, but it's unlikely.
>> snippet of code:
>> self.worker = MyClass()
>> self.workerThread = QtCore.QThread()
>> The trouble is when the user wants to download multiple files at once.
>> In my current implementation that all works fine and I see multiple
>> progress bars do there thing.
>> However, there are cases when I need to force the download threads to be
>> synchronous. I had hoped that I can use QThreadPool with QThreads, but
>> turns out I need QRunnables in this case, and those don't have the same
>> signals as QThread.
> Why do you need to force them to be synchronous? And synchronous with what?
> With each other? Or do you mean sync() in the file saving?
> Finally, what does being synchronous have to do with signals?
>> So my question is:
>> Is there a good way to use QThreads in a queue which is controlled by
>> the main thread, or should I re-write my code and subclass QRunnable to
>> add the signals I need (i.e. the ones that QThread has by default)?
> The whole point of QThread is that the code it runs is independent of anything
> else. Only the OS scheduler decides when it's time to run it or suspend it.
>> In the latter case I guess I'd have to inherit from both QObject and
>> QRunnable, is this ok?
> But we still don't understand what you're trying to do. All I can tell you is
> that you don't need to do what you're trying to do, since you don't need
> threads in the first place.
More information about the Interest