Skip to content

Add progress callback#74

Open
869570967 wants to merge 6 commits into
henon:mainfrom
869570967:main
Open

Add progress callback#74
869570967 wants to merge 6 commits into
henon:mainfrom
869570967:main

Conversation

@869570967

Copy link
Copy Markdown
Contributor
  1. Expose the progress callback of Downloader.Download step by step to external interfaces.
  2. Add an Action progress parameter to RunCommand, and also add an Action progress parameter to PipInstallModule, which calls it.

Purpose: When calling functions like await Installer.TryInstallPip(); and await Installer.PipInstallModule("torch", progress: progress); sometimes, due to network issues or very large packages, the program has to wait a long time without any progress feedback. Simply showing a loading spinner isn’t ideal, so here we add a progress callback parameter to make it easier to display the current progress in real time.

PS: The code was implemented using AI, and self-testing shows no issues so far. Here's my test code—you can also try it out to see if it works. If there are no problems, it can be merged and published to NuGet (pre-release is fine too). I'm a bit pressed to use it. Thanks a lot!

`using Python.Included;

namespace PythonDemo
{
internal class Program
{
static async Task Main(string[] args)
{
Installer.LogMessage += Installer_LogMessage;
//Console.WriteLine("Hello, World!");
await Installer.SetupPython();
await Installer.TryInstallPip();
Action progress = p =>
{
Console.WriteLine(p);
};
await Installer.PipInstallModule("torch", progress: progress);
}

    private static void Installer_LogMessage(string obj)
    {
        Console.WriteLine(obj);
    }
}

}
`

@869570967

Copy link
Copy Markdown
Contributor Author

Here are my test results:
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant