Skip to content

Commit 269b1bd

Browse files
committed
Fix trial cancellation bug
1 parent 9647027 commit 269b1bd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Microsoft.ML.AutoML/AutoMLExperiment/Runner/SweepablePipelineRunner.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

1616
namespace Microsoft.ML.AutoML
1717
{
18-
internal class SweepablePipelineRunner : ITrialRunner
18+
public class SweepablePipelineRunner : ITrialRunner
1919
{
2020
private MLContext? _mLContext;
2121
private readonly IEvaluateMetricManager _metricManager;
2222
private readonly IDatasetManager _datasetManager;
2323
private readonly SweepablePipeline _pipeline;
2424
private readonly IChannel? _logger;
25+
private CancellationTokenRegistration _ctRegistration;
2526

2627
public SweepablePipelineRunner(MLContext context, SweepablePipeline pipeline, IEvaluateMetricManager metricManager, IDatasetManager datasetManager, IChannel? logger = null)
2728
{
@@ -91,13 +92,12 @@ public Task<TrialResult> RunAsync(TrialSettings settings, CancellationToken ct)
9192
{
9293
try
9394
{
94-
using (var ctRegistration = ct.Register(() =>
95+
_ctRegistration = ct.Register(() =>
9596
{
9697
_mLContext?.CancelExecution();
97-
}))
98-
{
99-
return Task.Run(() => Run(settings));
100-
}
98+
});
99+
100+
return Task.Run(() => Run(settings));
101101
}
102102
catch (Exception ex) when (ct.IsCancellationRequested)
103103
{

0 commit comments

Comments
 (0)