5
5
*
6
6
*/
7
7
8
+ use std:: sync:: Arc ;
9
+ use std:: sync:: Mutex ;
10
+ use std:: thread;
11
+
8
12
use crate :: connection_file:: ConnectionFile ;
9
13
use crate :: error:: Error ;
10
14
use crate :: language:: control_handler:: ControlHandler ;
@@ -19,10 +23,10 @@ use crate::socket::shell::Shell;
19
23
use crate :: socket:: socket:: Socket ;
20
24
use crate :: socket:: stdin:: Stdin ;
21
25
use crate :: stream_capture:: StreamCapture ;
22
- use std :: sync :: mpsc :: sync_channel ;
23
- use std :: sync :: mpsc :: { Receiver , SyncSender } ;
24
- use std :: sync :: { Arc , Mutex } ;
25
- use std :: thread ;
26
+
27
+ use crossbeam :: channel :: Receiver ;
28
+ use crossbeam :: channel :: Sender ;
29
+ use crossbeam :: channel :: bounded ;
26
30
use log:: { warn, info} ;
27
31
28
32
/// A Kernel represents a unique Jupyter kernel session and is the host for all
@@ -35,7 +39,7 @@ pub struct Kernel {
35
39
session : Session ,
36
40
37
41
/// Sends messages to the IOPub socket
38
- iopub_sender : SyncSender < IOPubMessage > ,
42
+ iopub_sender : Sender < IOPubMessage > ,
39
43
40
44
/// Receives message sent to the IOPub socket
41
45
iopub_receiver : Option < Receiver < IOPubMessage > > ,
@@ -55,12 +59,12 @@ impl Kernel {
55
59
pub fn new ( file : ConnectionFile ) -> Result < Kernel , Error > {
56
60
let key = file. key . clone ( ) ;
57
61
58
- let ( iopub_sender, iopub_receiver) = sync_channel :: < IOPubMessage > ( 10 ) ;
62
+ let ( iopub_sender, iopub_receiver) = bounded :: < IOPubMessage > ( 10 ) ;
59
63
60
64
Ok ( Self {
61
65
connection : file,
62
66
session : Session :: create ( key) ?,
63
- iopub_sender,
67
+ iopub_sender : iopub_sender ,
64
68
iopub_receiver : Some ( iopub_receiver) ,
65
69
} )
66
70
}
@@ -164,7 +168,7 @@ impl Kernel {
164
168
}
165
169
166
170
/// Returns a copy of the IOPub sending channel.
167
- pub fn create_iopub_sender ( & self ) -> SyncSender < IOPubMessage > {
171
+ pub fn create_iopub_sender ( & self ) -> Sender < IOPubMessage > {
168
172
self . iopub_sender . clone ( )
169
173
}
170
174
@@ -177,7 +181,7 @@ impl Kernel {
177
181
/// Starts the shell thread.
178
182
fn shell_thread (
179
183
socket : Socket ,
180
- iopub_sender : SyncSender < IOPubMessage > ,
184
+ iopub_sender : Sender < IOPubMessage > ,
181
185
shell_handler : Arc < Mutex < dyn ShellHandler > > ,
182
186
) -> Result < ( ) , Error > {
183
187
let mut shell = Shell :: new ( socket, iopub_sender. clone ( ) , shell_handler) ;
@@ -210,9 +214,7 @@ impl Kernel {
210
214
}
211
215
212
216
/// Starts the output capture thread.
213
- fn output_capture_thread (
214
- iopub_sender : SyncSender < IOPubMessage > ,
215
- ) -> Result < ( ) , Error > {
217
+ fn output_capture_thread ( iopub_sender : Sender < IOPubMessage > ) -> Result < ( ) , Error > {
216
218
let output_capture = StreamCapture :: new ( iopub_sender) ;
217
219
output_capture. listen ( ) ;
218
220
Ok ( ( ) )
0 commit comments