开发者

Threads in PyQt4

Im making a PyQt4 app which calls Imagemagick and ffmpeg, but it takes too much to complete the 开发者_如何学Pythontasks and im wondering if there is a way to implement threads to this, the app is going to run in a multicore machine, and some of the methods I have seen are not efficient enough. Thanks in advance


The answer is yes and no - you can use QThread for threading but you'll still be subject to the GIL, so your threads will run in serial.

You could try using multiprocessing to create a worker class in its own process and send work to it (or have it steal work from a queue), however this could introduce its own performance penalties in copying objects and sending objects between processes...


Having re-read your question, it looks like Imagemagick and ffmpeg are external executables, in which case the GIL is released while you wait for the process to execute. Can I ask how you run these though? I tend to find that it is better to create a work queue and an event loop. Each time round the event loop you check whether your running process(es) have finished and then get their output. For this subprocess.Popen is more useful than os.command.

If you use a QTimer you can utilise your QApplication's event loop, which also has the added benefit of allowing your GUI (assuming you have one) to be refreshed between ticks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜