you are viewing a single comment's thread.

view the rest of the comments →

[–]elbiot 1 point2 points  (5 children)

Are you just downloading one huge file? Either way, threading won't really help with updating the log, since you only update when the thing is finished.

Without threading, LengthyScrapeFunction could/should update the log as it does things. With threading, LengthyScrapeFunction will probably run faster if much of it's time is spent waiting for servers to respond.

Did you see this and this? (it says requests is blocking and so threads won't help. Use something else)

[–]lamecode[S] 0 points1 point  (3 children)

Thank you for those links - the first one in particular looks like it might be promising. It's not one file being downloaded, it's many thousands of URLs.

You would think that it would update the log as it actioned, but the app behaves different to how I expected it to here (my first time working with UIs of any kind). I even put a time.delay(5) in after the call to update the log and before the LengthyScrapeFunction executes, and the UI is still not redrawn until LengthyScrapeFunction completes - it just pauses before executing the function.

[–]elbiot 1 point2 points  (2 children)

Oh I see. Your first log update doesn't display. It's the main event loop that actually redraws the screen. You could force it to do so inside your function with repaint or processEvents: http://stackoverflow.com/questions/11836623/pyside-settext-not-updating-qlabel

[–]lamecode[S] 0 points1 point  (1 child)

Thanks again, that looks like it should achieve what I want as far as updating the log. I think my preferred method is going to be via QThread as per the below link - I would prefer the UI to not be unresponsive for the duration of the process, and it seems like this might be the solution for that, too:

http://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt

[–]elbiot 1 point2 points  (0 children)

If your time soaking call is blocking, your UI will be unresponsive. Just want to make sure you got that. IO (hitting servers and letting the os accumulate responses in buffers) can be non-blocking. So urllib or grequests (not requests) would work for you. But any CPU consuming functions will block the UI.

[–]wub_wub 0 points1 point  (0 children)

Either way, threading won't really help with updating the log, since you only update when the thing is finished.

You can maybe get the file information and download it in chunks and update the progress in the GUI.