Message Boards Message Boards

Avoid auto-update from GitHub and URLSaveAsynchronous hanging?

Posted 7 years ago

I was trying to make an auto-update script for my packages. It would find, download and install the latest version. The problem is that sometimes URLSaveAsynchronous hangs. This happens more often on Windows than on other platforms, but it doesn't always happen. The frustrating thing is that since it happens randomly, I can't easy test for the reason.

Does anyone have a clue about what may be wrong?

The piece of code that hangs:

progress = 0.;
ProgressIndicator[Dynamic[progress]];
URLSaveAsynchronous[
  "https://github.com/szhorvat/MaTeX/releases/download/v1.6.2/MaTeX-1.6.2.paclet", 
  CreateFile[],  
  If[#2 === "progress", progress = Quiet[#3[[1]]/#3[[2]]] ] &,
  "Progress" -> True
 ]

At this moment I am really not sure whether the hang is related to the progress indicator. I observed the problem on all OSs, but it happened most often on Windows with M11.0.

The same thing in context is below. Note that the code is intended to be compatible with M10.0. I know that there are newer functions for some of these things.

updateMaTeX[] :=
  Module[{json, download, target, progress = 0.},
    Check[
      json = Import["https://api.github.com/repos/szhorvat/MaTeX/releases/latest", "JSON"];
      download = Lookup[First@Lookup[json, "assets"], "browser_download_url"];
      target = FileNameJoin[{CreateDirectory[], "MaTeX.paclet"}];
      PrintTemporary@ProgressIndicator[Dynamic[progress]];
      WaitAsynchronousTask@URLSaveAsynchronous[
        download, target,
        If[#2 === "progress", progress = Quiet[#3[[1]]/#3[[2]]] ] &,
        "Progress" -> True
      ]
      ,
      Return[$Failed]
    ];
    If[FileExistsQ[target], PacletInstall[target], $Failed]
  ]
POSTED BY: Szabolcs Horvát
3 Replies

Oh, the problem is specific to WaitAsynchronousTask / URLSaveAsynchronous. Of course, there are lots of other ways if you don't use these.

POSTED BY: Ilian Gachevski

Thanks for confirming this! It was driving me crazy.

Do you mean that there isn't a workaround even if I am willing to give up the progress bar? There are other functions, such as URLSave, URLDownload (v11 only), Export["file", Import["http://...", "String"], "String"], etc. Should I try these instead or do they all use the same back end to download things?

POSTED BY: Szabolcs Horvát

I think this is a known issue and is expected to be addressed in the next release.

The only workaround I am aware of is to set the "Timeout" option of WaitAsynchronousTask.

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract