libURLDownloadToFile making the UI unresponsive

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

libURLDownloadToFile making the UI unresponsive

Post by Ledigimate » Thu Mar 07, 2019 5:34 pm

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?
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

Klaus
Posts: 10969
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by Klaus » Thu Mar 07, 2019 5:51 pm

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

SparkOut
Posts: 1928
Joined: Sun Sep 23, 2007 4:58 pm

Re: libURLDownloadToFile making the UI unresponsive

Post by SparkOut » Thu Mar 07, 2019 6:14 pm

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.

Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

Re: libURLDownloadToFile making the UI unresponsive

Post by Ledigimate » Thu Mar 07, 2019 6:28 pm

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
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

Klaus
Posts: 10969
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by Klaus » Thu Mar 07, 2019 7:29 pm

What SparkOut said, we need to look at your handler(s) to be sure.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2334
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by jmburnod » Thu Mar 07, 2019 8:43 pm

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

Klaus
Posts: 10969
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by Klaus » Fri Mar 08, 2019 2:35 pm

Quick guess based on Jean-Marcs posting:
Maybe setting -> the socketTimeoutInterval to a higher value (default = 10000) will help?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2334
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by jmburnod » Fri Mar 08, 2019 5:51 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2334
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by jmburnod » Sat Mar 09, 2019 11:05 am

Three tries worked as expected with socketTimeoutInterval = 10000 or 15000.
That sound like a server problem no ?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6622
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by FourthWorld » Sat Mar 09, 2019 5:57 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

Re: libURLDownloadToFile making the UI unresponsive

Post by Ledigimate » Tue Mar 12, 2019 10:49 am

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.
downloadTest.zip
downloadTest.livecode
(2.77 KiB) Downloaded 11 times
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6622
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: libURLDownloadToFile making the UI unresponsive

Post by FourthWorld » Tue Mar 12, 2019 4:38 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1986
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: libURLDownloadToFile making the UI unresponsive

Post by [-hh] » Wed Mar 13, 2019 10:12 pm

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
shiftLock happens

Post Reply

Return to “Talking LiveCode”