14
14
try :
15
15
import ipykernel
16
16
17
- USAGE_IS_SUPPORTED = version .parse ("6.9.0" ) <= version .parse (ipykernel .__version__ )
17
+ IPYKERNEL_VERSION = ipykernel .__version__
18
+ USAGE_IS_SUPPORTED = version .parse ("6.9.0" ) <= version .parse (IPYKERNEL_VERSION )
18
19
except ImportError :
19
20
USAGE_IS_SUPPORTED = False
21
+ IPYKERNEL_VERSION = None
20
22
21
23
22
24
class ApiHandler (APIHandler ):
@@ -92,7 +94,12 @@ class KernelUsageHandler(APIHandler):
92
94
@web .authenticated
93
95
async def get (self , matched_part = None , * args , ** kwargs ):
94
96
if not USAGE_IS_SUPPORTED :
95
- self .write (json .dumps ({}))
97
+ self .write (json .dumps ({
98
+ "content" : {
99
+ "reason" : "not_supported" ,
100
+ "kernel_version" : IPYKERNEL_VERSION
101
+ }
102
+ }))
96
103
return
97
104
98
105
kernel_id = matched_part
@@ -112,11 +119,16 @@ async def get(self, matched_part=None, *args, **kwargs):
112
119
timeout_ms = 6_000
113
120
events = dict (await poller .poll (timeout_ms ))
114
121
if control_socket not in events :
115
- self .write (json .dumps ({}))
122
+ self .write (json .dumps ({
123
+ "content" : {"reason" : "timeout" , "timeout_ms" : timeout_ms },
124
+ "kernel_id" : kernel_id
125
+ }))
116
126
else :
117
127
res = client .control_channel .get_msg (timeout = 0 )
118
128
if isawaitable (res ):
119
129
# control_channel.get_msg may return a Future,
120
130
# depending on configured KernelManager class
121
131
res = await res
132
+ if res :
133
+ res ["kernel_id" ] = kernel_id
122
134
self .write (json .dumps (res , default = date_default ))
0 commit comments