Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not sure this object correctly disposes itself? #114

Open
pjsgsy opened this issue Feb 8, 2025 · 1 comment
Open

Not sure this object correctly disposes itself? #114

pjsgsy opened this issue Feb 8, 2025 · 1 comment

Comments

@pjsgsy
Copy link

pjsgsy commented Feb 8, 2025

Just an observation based on a week or so of using this. It sometimes seems to still be running operations, after it gets disposed of, resulting in this error

System.NullReferenceException: Object reference not set to an instance of an object. Total t: 10:20:27.3523791 01:30:32
at ShellProgressBar.ProgressBar.DisplayProgress()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()

This is odd, because when I first came across it, and for performance reasons, I set the option which I believed was supposed to disable the timer

    var options = new ProgressBarOptions
    {
        ProgressCharacter = '─',
        ProgressBarOnBottom = true,
        DisplayTimeInRealTime = false
    };

Anyway - Simple structure

      `using (var pbar = new ProgressBar(totalTicks, "Training... (you may early terminate by pressing 'X')", options))
      {
      pbar.Tick($"epoch: {epoch} element: {i,6}, loss: {totalLoss / (double)i:0.00000
      
       System.Threading.Thread.Sleep(50); // small delay to prevent any issues with progress bar desposed before finishing update
      }

`

I found it necessary to add that .Sleep to prevent it happening almost all the time in fast loops. Increase the timer and the problem gets less, but this of course slows down your training loops. Pretty sure the issue is the timer is still running after the loop is finished with the pbar object, but maybe I am doing something really silly? ;)

I did take a quick look at the code. Here, not sure why a new timer is created and displayprogress not just run, but I'm sure it is needed for something.

		if (this.Options.DisplayTimeInRealTime)
			_timer = new Timer((s) => OnTimerTick(), null, 500, 500);
		else //draw once
			_timer = new Timer((s) =>
			{
				_timer.Dispose();
				DisplayProgress();
			}, null, 0, 1000);

Just reporting it as coming back to desk alffer leaving a long process running and it bailed with the error after about 6 hours of work :(

@pjsgsy pjsgsy closed this as completed Feb 9, 2025
@pjsgsy pjsgsy reopened this Feb 9, 2025
@pjsgsy
Copy link
Author

pjsgsy commented Feb 9, 2025

It seems even with the delay, this happens once in a while... Other than not disposing of it, not sure how to work around this one

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

No branches or pull requests

1 participant