예제 #1
0
        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);
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
 public Task ExecuteTextAsync(string text, PythonEvaluationResultReprKind reprKind, Action <PythonEvaluationResult> completion, CancellationToken ct)
 {
     return(_thread.Process.ExecuteTextAsync(text, reprKind, this, completion, ct));
 }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 public void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, Action <PythonEvaluationResult> completion)
 {
     _thread.Process.ExecuteText(text, reprKind, this, completion);
 }
예제 #7
0
        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;
        }
예제 #8
0
 public void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, Action<PythonEvaluationResult> completion) {
     _thread.Process.ExecuteText(text, reprKind, this, completion);
 }