public Task <PythonEvaluationResult> ExecuteTextAsync(string text, PythonEvaluationResultReprKind reprKind = PythonEvaluationResultReprKind.Normal) { var tcs = new TaskCompletionSource <PythonEvaluationResult>(); EventHandler <ProcessExitedEventArgs> processExited = delegate { tcs.TrySetCanceled(); }; tcs.Task.ContinueWith(_ => _thread.Process.ProcessExited -= processExited); _thread.Process.ProcessExited += processExited; ExecuteText(text, reprKind, result => { tcs.TrySetResult(result); }); return(tcs.Task); }
public async Task <PythonEvaluationResult> ExecuteTextAsync(string text, PythonEvaluationResultReprKind reprKind = PythonEvaluationResultReprKind.Normal, CancellationToken ct = default(CancellationToken)) { var tcs = new TaskCompletionSource <PythonEvaluationResult>(); var cancellationRegistration = ct.Register(() => tcs.TrySetCanceled()); EventHandler <ProcessExitedEventArgs> processExited = delegate { tcs.TrySetCanceled(); }; _thread.Process.ProcessExited += processExited; try { await ExecuteTextAsync(text, reprKind, result => tcs.TrySetResult(result), ct); return(await tcs.Task); } finally { _thread.Process.ProcessExited -= processExited; cancellationRegistration.Dispose(); } }
public Task ExecuteTextAsync(string text, PythonEvaluationResultReprKind reprKind, Action <PythonEvaluationResult> completion, CancellationToken ct) { return(_thread.Process.ExecuteTextAsync(text, reprKind, this, completion, ct)); }
private void EvalTest(string filename, int lineNo, string frameName, int frameIndex, PythonEvaluationResultReprKind reprKind, EvalResult eval) { var debugger = new PythonDebugger(); PythonThread thread = null; var process = DebugProcess(debugger, DebuggerTestPath + filename, (newproc, newthread) => { var breakPoint = newproc.AddBreakPoint(filename, lineNo); breakPoint.Add(); thread = newthread; }); AutoResetEvent brkHit = new AutoResetEvent(false); process.BreakpointHit += (sender, args) => { brkHit.Set(); }; try { process.Start(); AssertWaited(brkHit); var frames = thread.Frames; PythonEvaluationResult obj = null; string errorMsg; if (eval.IsError) { Assert.IsFalse(frames[frameIndex].TryParseText(eval.Expression, out errorMsg), "should not have been able to parse expression"); Assert.AreEqual(eval.ExceptionText, errorMsg); } else { Assert.IsTrue(frames[frameIndex].TryParseText(eval.Expression, out errorMsg), "failed to parse expression"); Assert.IsNull(errorMsg); Assert.AreEqual(frameName, frames[frameIndex].FunctionName); var timeoutToken = new CancellationTokenSource(10000).Token; obj = frames[frameIndex].ExecuteTextAsync(eval.Expression, reprKind) .ContinueWith(t => t.Result, timeoutToken, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current) .GetAwaiter().GetResult(); eval.Validate(obj); } process.Continue(); WaitForExit(process); process = null; } finally { if (process != null) { process.Terminate(); WaitForExit(process, assert: false); } } }
internal void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, PythonStackFrame pythonStackFrame, Action<PythonEvaluationResult> completion) { int executeId = _ids.Allocate(); DebugWriteCommand("ExecuteText to thread " + pythonStackFrame.Thread.Id + " " + executeId); lock (_pendingExecutes) { _pendingExecutes[executeId] = new CompletionInfo(completion, text, pythonStackFrame); } lock (_streamLock) { _stream.Write(ExecuteTextCommandBytes); _stream.WriteString(text); _stream.WriteInt64(pythonStackFrame.Thread.Id); _stream.WriteInt32(pythonStackFrame.FrameId); _stream.WriteInt32(executeId); _stream.WriteInt32((int)pythonStackFrame.Kind); _stream.WriteInt32((int)reprKind); } }
public void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, Action <PythonEvaluationResult> completion) { _thread.Process.ExecuteText(text, reprKind, this, completion); }
public Task<PythonEvaluationResult> ExecuteTextAsync(string text, PythonEvaluationResultReprKind reprKind = PythonEvaluationResultReprKind.Normal) { var tcs = new TaskCompletionSource<PythonEvaluationResult>(); EventHandler<ProcessExitedEventArgs> processExited = delegate { tcs.TrySetCanceled(); }; tcs.Task.ContinueWith(_ => _thread.Process.ProcessExited -= processExited); _thread.Process.ProcessExited += processExited; ExecuteText(text, reprKind, result => { tcs.TrySetResult(result); }); return tcs.Task; }
public void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, Action<PythonEvaluationResult> completion) { _thread.Process.ExecuteText(text, reprKind, this, completion); }