Modify

Opened 12 years ago

Closed 12 years ago

#437 closed Bug (Wont Fix)

InetGet in background mode - loop not responding when site overloaded

Reported by: Zedna Owned by:
Milestone: Component: AutoIt
Version: 3.2.10.0 Severity: None
Keywords: Cc:

Description

InetGet in background mode - loop not responding

I have created small utility Radar
which downloads actual Czech meteorological radar pictures
and shows them on my GUI in loop (animation).

See whole code/screenshot in this topic in Examples forum:
http://www.autoitscript.com/forum/index.php?showtopic=75659

But sometimes when WWW site is overloaded my While @InetGetActive loop is not responsive.
It should go through my loop and show progress of download
but there is executed only few (or no) loop cycles when site is overloaded
so user can't see progress or stop downloading.

Note: Normally when WWW site is working fine all in my script is working fine too
also with stopping download by Esc key

Here is commented core code:

 Status("Stahování dat " & $i+1 & "/" & $pocet_snimku) ; set statusbar text: Download of data 1/6
 $cas1 = TimerInit()

 Inetget($adresa & "data/" & $nazvy[$i], $soubor, 0, 1) ; get GIF file (one of 6 pictures)
 While @InetGetActive
   ; Esc (HotkeySet) can set this global flag/variable when user wants to stop download
 	If $zastavit_stahovani Then 
 		InetGet("abort")
 		FileDelete($soubor)
 		ExitLoop 2 ; stop download of all pictures
 	EndIf

 	; if download last more than timeout defined in INI file then abort
 	$cas2 = TimerDiff($cas1)
 	If $cas2 > $timeout Then 
 		InetGet("abort")
 		FileDelete($soubor)
 		ExitLoop ; stop download of current picture
 	EndIf

 	; if download last more than 2s then show also % of download progress
 	If $cas2 > 2000 Then
 		Status("Stahování dat " & $i+1 & "/" & $pocet_snimku & " (" & Int(@InetGetBytesRead / $size * 100) & "%)")
 		Sleep(250)
 	Else
 		Sleep(50)
 	EndIf
 Wend

Attachments (0)

Change History (5)

comment:1 follow-up: Changed 12 years ago by Valik

I don't think there's much that can be done about this. When a download is stopped, it can block for a little bit. The API doesn't always honor the cancel request immediately. AutoIt internally blocks until the background thread is complete because otherwise it would report True for @InetGetActive checked immediately after InetGet("abort"). Basically, there's blocking code in place to prevent an obvious race condition. The flip side of that is short-circuiting the blocking code and making sure @InetGetActive returns false when it should. The problem there becomes it would be possible to start a second download before the first one was canceled. This would lead to a hard crash since a shared data structure is used since we only allow one download.

In short, my best guess looking at AutoIt's implementation and your code is that everything is working correctly. All the synchronization code must be there to prevent crashing or AutoIt lying about it's state.

Before I close this, I'll just ask this. Can you confirm the code is blocking at InetGet("abort")? I didn't run or test your code, I just looked at AutoIt's internals to see where it could be blocking at and InetGet("abort") is all I see. I want to make sure that's what it really is before I close this.

comment:2 in reply to: ↑ 1 ; follow-up: Changed 12 years ago by Zedna

Replying to Valik:

Before I close this, I'll just ask this. Can you confirm the code is blocking at InetGet("abort")? I didn't run or test your code, I just looked at AutoIt's internals to see where it could be blocking at and InetGet("abort") is all I see. I want to make sure that's what it really is before I close this.

I can't confirm this because when WWW site is busy/overloaded
it looks like program flow is not inside While @InetGetActive loop.
It looks like evaluating of @InetGetActive macro blocks program flow.

With InetGet('abort') there is no problem when WWW site is responding correctly.
In this case when I manually stop download by Esc then download stops OK.

But when WWW site is busy/overloaded program never/very late reaches code/conditions inside my While @InetGetActive loop. There is code for displaying progress (percentage) of download when it takes more than two seconds but this code is never/very late executed in this case. So I don't think this problem can be in relation with InetGet('abort').

comment:3 in reply to: ↑ 2 Changed 12 years ago by Zedna

Replying to Zedna:

It looks like evaluating of @InetGetActive macro blocks program flow.

Or evaluating of @InetGetBytesRead macro may block program flow.

comment:4 Changed 12 years ago by Zedna

Sorry - now as I think more about that maybe InetGet('abort') may be "blocking" as you said.
But I'm not sure.

comment:5 Changed 12 years ago by Valik

  • Resolution set to Wont Fix
  • Status changed from new to closed

I'm closing this as "Won't Fix". There isn't a way to fix this which will work correctly in all cases. The current method is the least weird of all the various possible outcomes.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.