Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit ff4f5af

Browse files
committed
Added execute reply message
1 parent 6fbac23 commit ff4f5af

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/Actions/ExecuteAction.php

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33

44
namespace Litipk\JupyterPHP\Actions;
55

6-
76
use Litipk\JupyterPHP\JupyterBroker;
87
use Psy\Exception\BreakException;
98
use Psy\Exception\ThrowUpException;
109
use Psy\ExecutionLoop\Loop;
1110
use Psy\Shell;
1211
use React\ZMQ\SocketWrapper;
1312

14-
1513
final class ExecuteAction implements Action
1614
{
1715
/** @var JupyterBroker */
@@ -31,9 +29,12 @@ final class ExecuteAction implements Action
3129

3230
/** @var string */
3331
private $code;
34-
32+
33+
/** @var bool */
34+
private $silent;
35+
3536
/** @var int */
36-
private $execCount;
37+
private $execCount = 0;
3738

3839
/**
3940
* ExecuteAction constructor.
@@ -43,9 +44,11 @@ final class ExecuteAction implements Action
4344
* @param Shell $shellSoul
4445
*/
4546
public function __construct(
46-
JupyterBroker $broker, SocketWrapper $iopubSocket, SocketWrapper $shellSocket, Shell $shellSoul
47-
)
48-
{
47+
JupyterBroker $broker,
48+
SocketWrapper $iopubSocket,
49+
SocketWrapper $shellSocket,
50+
Shell $shellSoul
51+
) {
4952
$this->broker = $broker;
5053
$this->iopubSocket = $iopubSocket;
5154
$this->shellSocket = $shellSocket;
@@ -54,32 +57,50 @@ public function __construct(
5457

5558
public function call(array $header, array $content, $zmqId = null)
5659
{
57-
$this->broker->send(
58-
$this->iopubSocket, 'status', ['execution_state' => 'busy'], $header
59-
);
60+
$this->broker->send($this->iopubSocket, 'status', ['execution_state' => 'busy'], $header);
6061

6162
$this->header = $header;
62-
$this->execCount = isset($content->execution_count) ? $content->execution_count : 0;
6363
$this->code = $content['code'];
64+
$this->silent = $content['silent'];
65+
66+
if (!$this->silent) {
67+
$this->execCount = $this->execCount + 1;
68+
69+
$this->broker->send(
70+
$this->iopubSocket,
71+
'execute_input',
72+
['code' => $this->code, 'execution_count' => $this->execCount],
73+
$this->header
74+
);
75+
}
6476

6577
$closure = $this->getClosure();
6678
$closure();
79+
80+
$replyContent = [
81+
'status' => 'ok',
82+
'execution_count' => $this->execCount,
83+
'payload' => [],
84+
'user_expressions' => new \stdClass
85+
];
86+
87+
$this->broker->send($this->shellSocket, 'execute_reply', $replyContent, $this->header, [], $zmqId);
88+
89+
$this->broker->send($this->iopubSocket, 'status', ['execution_state' => 'idle'], $this->header);
6790
}
6891

6992
/**
7093
* @param string $message
7194
*/
7295
public function notifyMessage($message)
7396
{
74-
$this->broker->send($this->shellSocket, 'execute_reply', ['status' => 'ok'], $this->header);
75-
$this->broker->send($this->iopubSocket, 'stream', ['name' => 'stdout', 'data' => $message], $this->header);
97+
$this->broker->send($this->iopubSocket, 'stream', ['name' => 'stdout', 'text' => $message], $this->header);
7698
$this->broker->send(
7799
$this->iopubSocket,
78100
'execute_result',
79-
['execution_count' => $this->execCount + 1, 'data' => $message, 'metadata' => new \stdClass],
101+
['execution_count' => $this->execCount, 'data' => ['text/plain' => $message], 'metadata' => new \stdClass],
80102
$this->header
81103
);
82-
$this->broker->send($this->iopubSocket, 'status', ['execution_state' => 'idle'], $this->header);
83104
}
84105

85106
/**

0 commit comments

Comments
 (0)