public override async Task <ExecutionResult> ExecuteCodeAsync(string text) { var tcs = new TaskCompletionSource <ExecutionResult>(); var ct = new CancellationToken(); var cancellationRegistration = ct.Register(() => tcs.TrySetCanceled()); EventHandler <ProcessExitedEventArgs> processExited = delegate { tcs.TrySetCanceled(); }; EventHandler <OutputEventArgs> debuggerOutput = (object sender, OutputEventArgs e) => { if (e.IsStdOut) { WriteOutput(e.Output, addNewline: false); } else { WriteError(e.Output, addNewline: false); } }; Action <PythonEvaluationResult> resultReceived = (PythonEvaluationResult result) => { if (!string.IsNullOrEmpty(result.ExceptionText)) { tcs.TrySetResult(ExecutionResult.Failure); } else { tcs.TrySetResult(ExecutionResult.Success); } }; _process.ProcessExited += processExited; _process.DebuggerOutput += debuggerOutput; try { if (_currentScopeName == CurrentFrameScopeFixedName) { var frame = GetFrames().SingleOrDefault(f => f.FrameId == _frameId); if (frame != null) { await _process.ExecuteTextAsync(text, PythonEvaluationResultReprKind.Normal, frame, true, resultReceived, ct); } else { WriteError(Strings.DebugReplCannotRetrieveFrameError); tcs.TrySetResult(ExecutionResult.Failure); } } else { await _process.ExecuteTextAsync(text, PythonEvaluationResultReprKind.Normal, _currentScopeName, true, resultReceived, ct); } return(await tcs.Task); } finally { _process.ProcessExited -= processExited; _process.DebuggerOutput -= debuggerOutput; cancellationRegistration.Dispose(); } }