33
33
class ExecutionStack :
34
34
"""Execution request stack.
35
35
36
+ It is keeping track of the execution requests.
37
+
36
38
The request result can only be queried once.
37
39
"""
38
40
@@ -44,11 +46,12 @@ def __del__(self):
44
46
for task in filter (lambda t : not t .cancelled (), self .__tasks .values ()):
45
47
task .cancel ()
46
48
47
- def cancel (self , uid : str ) -> None :
49
+ def cancel (self , kernel_id : str , uid : str ) -> None :
48
50
"""Cancel the request ``uid``.
49
51
50
52
Args:
51
- uid: Task identifier
53
+ kernel_id : Kernel identifier
54
+ uid : Request identifier
52
55
"""
53
56
get_logger ().debug (f"Cancel request { uid } ." )
54
57
if uid not in self .__tasks :
@@ -57,18 +60,18 @@ def cancel(self, uid: str) -> None:
57
60
self .__tasks [uid ].cancel ()
58
61
59
62
def get (self , kernel_id : str , uid : str ) -> t .Any :
60
- """Get the request ``uid`` results or None.
63
+ """Get the request ``uid`` results, its pending input or None.
61
64
62
65
Args:
63
66
kernel_id : Kernel identifier
64
- uid : Request index
67
+ uid : Request identifier
65
68
66
69
Returns:
67
- Any: None if the request is pending else its result
70
+ Any: None if the request is pending else its result or the pending input.
68
71
69
72
Raises:
70
- ValueError: If the request `uid` does not exists.
71
- asyncio.CancelledError: If the request `uid` was cancelled.
73
+ ValueError: If the request `` uid` ` does not exists.
74
+ asyncio.CancelledError: If the request `` uid` ` was cancelled.
72
75
"""
73
76
if uid not in self .__tasks :
74
77
raise ValueError (f"Request { uid } does not exists." )
@@ -88,20 +91,25 @@ def put(
88
91
"""Add a asynchronous execution request.
89
92
90
93
Args:
91
- task: Asynchronous task
92
- *args : arguments of the task
94
+ km: Kernel manager
95
+ snippet: Snippet to be executed
96
+ ycell: [optional] The cell to update with the execution results
93
97
94
98
Returns:
95
99
Request identifier
96
100
"""
97
101
uid = str (uuid .uuid4 ())
98
102
99
103
self .__tasks [uid ] = asyncio .create_task (
100
- execute_task (uid , km , snippet , ycell , partial (self ._stdin_hook , km .kernel_id ))
104
+ _execute_task (uid , km , snippet , ycell , partial (self ._stdin_hook , km .kernel_id ))
101
105
)
102
106
return uid
103
107
104
108
def _stdin_hook (self , kernel_id : str , msg : dict ) -> None :
109
+ """Callback on stdin message.
110
+
111
+ It will register the pending input as temporary answer to the execution request.
112
+ """
105
113
get_logger ().info (f"Execution request { kernel_id } received a input request { msg !s} " )
106
114
if kernel_id in self .__pending_inputs :
107
115
get_logger ().error (
@@ -116,7 +124,7 @@ def _stdin_hook(self, kernel_id: str, msg: dict) -> None:
116
124
}
117
125
118
126
119
- async def execute_task (
127
+ async def _execute_task (
120
128
uid ,
121
129
km : jupyter_client .manager .KernelManager ,
122
130
snippet : str ,
@@ -335,7 +343,15 @@ class InputHandler(ExtensionHandlerMixin, APIHandler):
335
343
336
344
@tornado .web .authenticated
337
345
async def post (self , kernel_id : str ) -> None :
338
- body = self .get_json_body ()
346
+ """
347
+ Send an input value to kernel ``kernel_id``.
348
+
349
+ Args:
350
+ kernel_id: Kernel identifier
351
+
352
+ Json Body Required:
353
+ input (str): Input value
354
+ """
339
355
340
356
try :
341
357
km = self .kernel_manager .get_kernel (kernel_id )
@@ -344,6 +360,7 @@ async def post(self, kernel_id: str) -> None:
344
360
get_logger ().error (msg , exc_info = e )
345
361
raise tornado .web .HTTPError (status_code = HTTPStatus .NOT_FOUND , reason = msg ) from e
346
362
363
+ body = self .get_json_body ()
347
364
client = km .client ()
348
365
349
366
try :
@@ -369,7 +386,7 @@ def initialize(
369
386
370
387
@tornado .web .authenticated
371
388
def get (self , kernel_id : str , request_id : str ) -> None :
372
- """`GET /api/kernels/<kernel_id>/requests/<id >` Returns the request ``uid`` status.
389
+ """`GET /api/kernels/<kernel_id>/requests/<request_id >` Returns the request ``uid`` status.
373
390
374
391
Status are:
375
392
@@ -379,7 +396,8 @@ def get(self, kernel_id: str, request_id: str) -> None:
379
396
* 500: Request ends with errors
380
397
381
398
Args:
382
- index: Request identifier
399
+ kernel_id: Kernel identifier
400
+ request_id: Request identifier
383
401
384
402
Raises:
385
403
404 if request ``uid`` does not exist
@@ -405,13 +423,14 @@ def get(self, kernel_id: str, request_id: str) -> None:
405
423
406
424
@tornado .web .authenticated
407
425
def delete (self , kernel_id : str , request_id : str ) -> None :
408
- """`DELETE /api/kernels/<kernel_id>/requests/<id >` cancels the request ``uid``.
426
+ """`DELETE /api/kernels/<kernel_id>/requests/<request_id >` cancels the request ``uid``.
409
427
410
428
Status are:
411
429
* 204: Request cancelled
412
430
413
431
Args:
414
- uid: Request uid
432
+ kernel_id: Kernel identifier
433
+ request_id: Request identifier
415
434
416
435
Raises:
417
436
404 if request ``uid`` does not exist
0 commit comments