-
Notifications
You must be signed in to change notification settings - Fork 25
Add Jupyter DAP handler #1171
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
Add Jupyter DAP handler #1171
Changes from all commits
89c680b
e851d31
1b9cd4d
2fb7c17
f5f8140
1e9d0ae
91a98f1
ebceffa
b35379f
ea728ae
05161db
dc61b06
17ad2e2
9a46c49
998930e
3575688
d0d8015
413eaf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,23 +5,21 @@ | |
| * | ||
| */ | ||
|
|
||
| use std::sync::Arc; | ||
| use std::sync::Mutex; | ||
|
|
||
| use crossbeam::channel::SendError; | ||
| use crossbeam::channel::Sender; | ||
| use futures::executor::block_on; | ||
| use log::error; | ||
| use log::info; | ||
| use log::trace; | ||
| use log::warn; | ||
| use stdext::result::ResultExt; | ||
| use stdext::unwrap; | ||
|
|
||
| use crate::error::Error; | ||
| use crate::language::control_handler::ControlHandler; | ||
| use crate::socket::iopub::IOPubContextChannel; | ||
| use crate::socket::iopub::IOPubMessage; | ||
| use crate::socket::Socket; | ||
| use crate::wire::debug_request::DebugRequest; | ||
| use crate::wire::interrupt_request::InterruptRequest; | ||
| use crate::wire::jupyter_message::JupyterMessage; | ||
| use crate::wire::jupyter_message::Message; | ||
|
|
@@ -33,15 +31,15 @@ use crate::wire::status::KernelStatus; | |
| pub struct Control { | ||
| socket: Socket, | ||
| iopub_tx: Sender<IOPubMessage>, | ||
| handler: Arc<Mutex<dyn ControlHandler>>, | ||
| handler: Box<dyn ControlHandler>, | ||
| stdin_interrupt_tx: Sender<bool>, | ||
| } | ||
|
|
||
| impl Control { | ||
| pub fn new( | ||
| socket: Socket, | ||
| iopub_tx: Sender<IOPubMessage>, | ||
| handler: Arc<Mutex<dyn ControlHandler>>, | ||
| handler: Box<dyn ControlHandler>, | ||
| stdin_interrupt_tx: Sender<bool>, | ||
| ) -> Self { | ||
| Self { | ||
|
|
@@ -73,6 +71,9 @@ impl Control { | |
|
|
||
| fn process_message(&self, message: Message) -> Result<(), Error> { | ||
| match message { | ||
| Message::DebugRequest(req) => { | ||
| self.handle_request(req, |r| self.handle_debug_request(r)) | ||
| }, | ||
| Message::ShutdownRequest(req) => { | ||
| self.handle_request(req, |r| self.handle_shutdown_request(r)) | ||
| }, | ||
|
|
@@ -130,11 +131,8 @@ impl Control { | |
| fn handle_shutdown_request(&self, req: JupyterMessage<ShutdownRequest>) -> Result<(), Error> { | ||
| info!("Received shutdown request, shutting down kernel: {:?}", req); | ||
|
|
||
| // Lock the control handler object on this thread | ||
| let control_handler = self.handler.lock().unwrap(); | ||
|
|
||
| let reply = unwrap!( | ||
| block_on(control_handler.handle_shutdown_request(&req.content)), | ||
| self.handler.handle_shutdown_request(&req.content), | ||
| Err(err) => { | ||
| log::error!("Failed to handle shutdown request: {err:?}"); | ||
| return Ok(()) | ||
|
|
@@ -156,6 +154,18 @@ impl Control { | |
| Ok(()) | ||
| } | ||
|
|
||
| fn handle_debug_request(&self, req: JupyterMessage<DebugRequest>) -> Result<(), Error> { | ||
| log::trace!("Received debug request: {:?}", req); | ||
|
|
||
| let Some(reply) = self.handler.handle_debug_request(&req.content).log_err() else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| req.send_reply(reply, &self.socket).log_err(); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn handle_interrupt_request(&self, req: JupyterMessage<InterruptRequest>) -> Result<(), Error> { | ||
| info!( | ||
| "Received interrupt request, asking kernel to stop: {:?}", | ||
|
|
@@ -169,11 +179,8 @@ impl Control { | |
| error!("Failed to send interrupt request: {:?}", err); | ||
| } | ||
|
|
||
| // Lock the control handler object on this thread | ||
| let control_handler = self.handler.lock().unwrap(); | ||
|
|
||
| let reply = unwrap!( | ||
| block_on(control_handler.handle_interrupt_request()), | ||
| self.handler.handle_interrupt_request(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened to allow us to remove all of this and the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've never needed amalthea handler methods to be async, and should move towards sync over time. I made that clean up for Control as I was in the neighborhood. |
||
| Err(err) => { | ||
| log::error!("Failed to handle interrupt request: {err:?}"); | ||
| return Ok(()) | ||
|
|
||
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's interesting how we never actually return an
Errorfrom these methods...