Page 1 of 1
libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 5:34 pm
by Ledigimate
Hi there
If I understand the LC dictionary correctly, libURLDownloadToFile is supposed to be non-blocking, but I get blocking behavior with large files.
I created an "Abort download" button to enable the user to cancel the download, but the button won't respond to mouse clicks while the download is in progress. Only after the download completes, the button catches up with the mouse clicks.
It only seems to happen with large files, i.e. files that take more than a few seconds to download.
Could this be a bug in the internet library?
Re: libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 5:51 pm
by Klaus
HI Ledigimate,
what platform are you experiencing this on?
What version of LC are you using?
Do you use the Community or Commercial version?
Best
Klaus
Re: libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 6:14 pm
by SparkOut
What is happening in the rest of the script? Do you have any wait or repeat statements? Maybe you are waiting for the file to download and "blocking" the script until the test for completion is met? If so, this would need a wait "with messages" statement, to allow housekeeping time for the engine to process messages generated by other scripts like your cancel button. If not, more details are needed.
Re: libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 6:28 pm
by Ledigimate
what platform are you experiencing this on?
Windows 10 Pro X64
What version of LC are you using?
version 8.1.10
Do you use the Community or Commercial version?
Community
Re: libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 7:29 pm
by Klaus
What SparkOut said, we need to look at your handler(s) to be sure.
Re: libURLDownloadToFile making the UI unresponsive
Posted: Thu Mar 07, 2019 8:43 pm
by jmburnod
I have a similar problem when i try to download a zip file 160 mo for 4000 files.
I often get an error "request timed out" (I used callback to see it)
No error when i download the same content file by file.
Kind regards
Jean-Marc
Re: libURLDownloadToFile making the UI unresponsive
Posted: Fri Mar 08, 2019 2:35 pm
by Klaus
Quick guess based on Jean-Marcs posting:
Maybe setting -> the socketTimeoutInterval to a higher value (default = 10000) will help?
Re: libURLDownloadToFile making the UI unresponsive
Posted: Fri Mar 08, 2019 5:51 pm
by jmburnod
Hi Klaus,
Thanks for suggestion.
I tried with a socketTimeoutInterval = 15000 without success, download is stopped with a time out error. (LC indy 9.01)
I will try again this night.
Kind regards
Jean-Marc
Re: libURLDownloadToFile making the UI unresponsive
Posted: Sat Mar 09, 2019 11:05 am
by jmburnod
Three tries worked as expected with socketTimeoutInterval = 10000 or 15000.
That sound like a server problem no ?
Re: libURLDownloadToFile making the UI unresponsive
Posted: Sat Mar 09, 2019 5:57 pm
by FourthWorld
If you use the callback message option the I/O should become async, allowing other messages processing such as UI handling. This is generally true of all socket operations in LiveCode.
Re: libURLDownloadToFile making the UI unresponsive
Posted: Tue Mar 12, 2019 10:49 am
by Ledigimate
I've discovered that the UI's unresponsiveness is proportional to the download speed.
When I test it using a web server with Gigabit download speeds, the Abort button won't respond to being pressed until after the download completes.
When I test it using a web server with slower download speeds, the Abort button responded when pressed.
I've attached a sample stack.
Re: libURLDownloadToFile making the UI unresponsive
Posted: Tue Mar 12, 2019 4:38 pm
by FourthWorld
Thanks for posting the test stack.
Have you had a chance to test that on non-Windows systems?
When it appears to hang, does Windows rename the title bar to include "(Application Unresponsive)"?
I'm wondering if this may be related to a deeper issue LC has with not integrating with the Win OS event loop gracefully.
Re: libURLDownloadToFile making the UI unresponsive
Posted: Wed Mar 13, 2019 10:12 pm
by [-hh]
Yes, libUrl is not blocking and it works here on MacOS 10.14, Win 7+10, linux (ubuntu 1604).
But LC is is not able of multitasking.
So it may be better to download your files
one after the other by using "send in time", not from a repeat loop.
A few issues:
1) You should cancel *item 1 of* a line of the pendingMessages not the full line.
2) Do NOT cancel ALL pending messages. This cannot work.
Instead
- write a download handler "ledigDownload p1,p2,p3,p4" (the p's are params you need) for one file only.
- send "ledigDownload p1,p2,p3,p4" for each single file.
Then use
Code: Select all
on cancelPendingMessages
repeat 2
repeat for each line L of the pendingMessages
if "ledigDownload" is item 3 of L then cancel item 1 of L
end repeat
end repeat
end cancelPendingMessages
Also you could use the following on openCard in case someone with an Indy license uses your stack:
Code: Select all
if there is a stack "tsNetLibURL"
then dispatch "revUnloadLibrary" to stack "tsNetLibURL" --> no problems with https