-
Notifications
You must be signed in to change notification settings - Fork 563
Kernel Interrupt api #414
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
Merged
colombod
merged 32 commits into
dotnet:master
from
colombod:feature/interrupt_evaluation
Sep 3, 2019
Merged
Kernel Interrupt api #414
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5dd3a49
wip
colombod 67e7aa2
add test
colombod df3ee45
InterruptExecution command
colombod a6fe0a5
wip
colombod 09ed47b
Merge branch 'master' into feature/interrupt_evaluation
colombod 638ac34
format file
colombod d48a0e5
Merge branch 'master' into feature/interrupt_evaluation
colombod e7c2939
Merge branch 'master' into feature/incomplete_submission
colombod f6c2d72
Merge branch 'master' into feature/interrupt_evaluation
colombod 07ba4d8
Merge branch 'master' into feature/split_value_events
colombod a65def9
split files
colombod 9a4a50d
Merge branch 'master' into feature/default_enum_value
colombod 02a5b28
Merge branch 'master' into feature/interrupt_evaluation
colombod 3a740e4
rename command and event
colombod 87224c3
wip
colombod c0f1246
Merge branch 'master' into feature/interrupt_evaluation
colombod bf5d857
Merge branch 'master' into feature/interrupt_evaluation
colombod b8730a5
rename command and event
colombod 3759d15
add handler tests
colombod de5291d
wire handler and kernel
colombod 7ed2d2f
is this the right thing to do???
colombod 2effa6b
wip
colombod ec13fd3
Merge branch 'master' into feature/interrupt_evaluation
colombod 47ba751
WIP
colombod 4c32f76
Merge branch 'master' into feature/interrupt_evaluation
colombod 16c1788
add locks
colombod d2d8562
fixed event publishing order
colombod 17c32fe
Merge branch 'master' into feature/interrupt_evaluation
colombod 7557550
separate files
colombod 42c965d
code formatted
colombod 1a3a1cc
rename command and event for current command cancellation
colombod 3ab8f75
unify cancellation check on source
colombod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Microsoft.DotNet.Interactive.Jupyter.Tests/InterruptRequestHandlerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Microsoft.DotNet.Interactive.Jupyter.Protocol; | ||
| using Recipes; | ||
| using WorkspaceServer.Kernel; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Jupyter.Tests | ||
| { | ||
| public class InterruptRequestHandlerTests | ||
| { | ||
| private readonly MessageSender _ioPubChannel; | ||
| private readonly MessageSender _serverChannel; | ||
| private readonly RecordingSocket _serverRecordingSocket; | ||
| private readonly RecordingSocket _ioRecordingSocket; | ||
| private readonly KernelStatus _kernelStatus; | ||
|
|
||
| public InterruptRequestHandlerTests() | ||
| { | ||
| var signatureValidator = new SignatureValidator("key", "HMACSHA256"); | ||
| _serverRecordingSocket = new RecordingSocket(); | ||
| _serverChannel = new MessageSender(_serverRecordingSocket, signatureValidator); | ||
| _ioRecordingSocket = new RecordingSocket(); | ||
| _ioPubChannel = new MessageSender(_ioRecordingSocket, signatureValidator); | ||
| _kernelStatus = new KernelStatus(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void cannot_handle_requests_that_are_not_InterruptRequest() | ||
| { | ||
| var kernel = new CSharpKernel(); | ||
| var handler = new InterruptRequestHandler(kernel); | ||
| var request = Message.Create(new DisplayData(), null); | ||
| Func<Task> messageHandling = () => handler.Handle(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus)); | ||
| messageHandling.Should().ThrowExactly<InvalidOperationException>(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task handles_InterruptRequest() | ||
| { | ||
| var kernel = new CSharpKernel(); | ||
| var handler = new InterruptRequestHandler(kernel); | ||
| var request = Message.Create(new InterruptRequest(), null); | ||
| await handler.Handle(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task sends_InterruptReply() | ||
| { | ||
| var kernel = new CSharpKernel(); | ||
| var handler = new InterruptRequestHandler(kernel); | ||
| var request = Message.Create(new InterruptRequest(), null); | ||
| await handler.Handle(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus)); | ||
|
|
||
| _serverRecordingSocket.DecodedMessages.SingleOrDefault(message => | ||
| message.Contains(MessageTypeValues.InterruptReply)) | ||
| .Should() | ||
| .NotBeNullOrWhiteSpace(); | ||
| } | ||
| } | ||
colombod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
64 changes: 64 additions & 0 deletions
64
Microsoft.DotNet.Interactive.Jupyter/InterruptRequestHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Reactive.Concurrency; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.DotNet.Interactive.Commands; | ||
| using Microsoft.DotNet.Interactive.Events; | ||
| using Microsoft.DotNet.Interactive.Jupyter.Protocol; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Jupyter | ||
| { | ||
| public class InterruptRequestHandler : RequestHandlerBase<InterruptRequest> | ||
| { | ||
|
|
||
| public InterruptRequestHandler(IKernel kernel, IScheduler scheduler = null) | ||
| : base(kernel, scheduler ?? CurrentThreadScheduler.Instance) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| protected override void OnKernelEvent(IKernelEvent @event) | ||
| { | ||
| switch (@event) | ||
| { | ||
| case CurrentCommandCancelled kernelInterrupted: | ||
| OnExecutionInterrupted(kernelInterrupted); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| private void OnExecutionInterrupted(CurrentCommandCancelled currentCommandCancelled) | ||
| { | ||
| if (InFlightRequests.TryRemove(currentCommandCancelled.Command, out var openRequest)) | ||
| { | ||
| // reply | ||
| var interruptReplyPayload = new InterruptReply(); | ||
|
|
||
| // send to server | ||
| var interruptReply = Message.CreateResponse( | ||
| interruptReplyPayload, | ||
| openRequest.Context.Request); | ||
|
|
||
| openRequest.Context.ServerChannel.Send(interruptReply); | ||
| openRequest.Context.RequestHandlerStatus.SetAsIdle(); | ||
| openRequest.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| public async Task Handle(JupyterRequestContext context) | ||
| { | ||
| var interruptRequest = GetJupyterRequest(context); | ||
|
|
||
| context.RequestHandlerStatus.SetAsBusy(); | ||
|
|
||
| var command = new CancelCurrentCommand(); | ||
|
|
||
| var openRequest = new InflightRequest(context, interruptRequest, 0); | ||
|
|
||
| InFlightRequests[command] = openRequest; | ||
|
|
||
| await Kernel.SendAsync(command); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,5 @@ private void OnKernelEvent(IKernelEvent @event, bool isComplete) | |
| openRequest.Dispose(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Microsoft.DotNet.Interactive.Jupyter/Protocol/InterruptReply.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Jupyter.Protocol | ||
| { | ||
| [JupyterMessageType(MessageTypeValues.InterruptReply)] | ||
| public class InterruptReply : JupyterMessageContent | ||
| { | ||
|
|
||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Microsoft.DotNet.Interactive.Jupyter/Protocol/InterruptRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Jupyter.Protocol | ||
| { | ||
| [JupyterMessageType(MessageTypeValues.InterruptRequest)] | ||
| public class InterruptRequest : JupyterMessageContent | ||
| { | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Microsoft.DotNet.Interactive/Commands/CancelCurrentCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Commands | ||
| { | ||
| public class CancelCurrentCommand : KernelCommandBase | ||
| { | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Microsoft.DotNet.Interactive/Events/CurrentCommandCancelled.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.DotNet.Interactive.Commands; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.Events | ||
| { | ||
| public class CurrentCommandCancelled:KernelEventBase | ||
| { | ||
| public CurrentCommandCancelled(IKernelCommand command) : base(command) | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we merge this one and the one below into one test as this one doesnt have any assertion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would throw if not using the right message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Thanks!