Skip to content

Commit 5ca29a8

Browse files
author
Dorian Birraux
committed
Merge pull request #246 in LCL/wolframclientforpython from feature/12.3-zmq-features to master
* commit '284dbdd4cd688a5f316f530d708486f7899651fe': SocketListen disabled but left in place for posterity Use SocketListen to evaluate message wrong color scheme for message name increase minor version new ZMQ module lazy starts during the function call. removing unfortunate use of the word slave test should not trigger lib installation updating minor version in paclet info introducing 12.3 functions
2 parents dd9cedf + 284dbdd commit 5ca29a8

7 files changed

Lines changed: 57 additions & 41 deletions

File tree

PacletInfo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Paclet[
22
Name -> "WolframClientForPython",
3-
Version -> "1.1.3",
3+
Version -> "1.1.5",
44
MathematicaVersion -> "11.3+",
55
Loading -> Automatic,
66
Extensions -> {}

docs/wri_theme/static/mma.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $green: rgb(67, 137, 88);
2929
color: $black;
3030
}
3131
.ne { // Messages (the "foo" in General::foo)
32-
color: $magenta;
32+
color: $black;
3333
}
3434
.nf { // Slots
3535
color: $green;

wolframclient/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
__name__ = "wolframclient"
44
__description__ = "A Python library with various tools to interact with the Wolfram Language and the Wolfram Cloud."
5-
__version__ = "1.1.4"
5+
__version__ = "1.1.5"
66
__author__ = "Wolfram Research"
77
__author_email__ = "support@wolfram.com, dorianb@wolfram.com, riccardod@wolfram.com"

wolframclient/cli/commands/test.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
from wolframclient.utils.importutils import module_path
1111

1212

13-
@to_tuple
14-
def dependencies():
15-
yield ("pytz", "2018.6")
16-
17-
if not six.JYTHON:
18-
yield ("numpy", not six.PY2 and "1.15.3" or None)
19-
yield ("pillow", "7.1.2")
20-
yield ("requests", "2.20.0")
21-
yield ("oauthlib", "2.1.0")
22-
yield ("pyzmq", "17.1.2")
23-
yield ("pandas", "1.0.4")
24-
yield ("unittest-xml-reporting", None)
25-
if not six.PY2:
26-
yield ("aiohttp", "3.6.2")
13+
# @to_tuple
14+
# def dependencies():
15+
# yield ("pytz", "2018.6")
16+
#
17+
# if not six.JYTHON:
18+
# yield ("numpy", not six.PY2 and "1.15.3" or None)
19+
# yield ("pillow", "7.1.2")
20+
# yield ("requests", "2.20.0")
21+
# yield ("oauthlib", "2.1.0")
22+
# yield ("pyzmq", "17.1.2")
23+
# yield ("pandas", "1.0.4")
24+
# yield ("unittest-xml-reporting", None)
25+
# if not six.PY2:
26+
# yield ("aiohttp", "3.6.2")
2727

2828

2929
class Command(SimpleCommand):
@@ -33,7 +33,7 @@ class Command(SimpleCommand):
3333

3434
modules = ["wolframclient.tests"]
3535

36-
dependencies = dependencies()
36+
dependencies = ()
3737

3838
def add_arguments(self, parser):
3939
parser.add_argument(

wolframclient/evaluation/kernel/initkernel.m

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(* ::Package:: *)
22

3-
(* Not useful since we apparently never receive multipart messages,
4-
no matter the total size (tested with 80MB) *)
3+
54
$NotSupportedVersionErrNo = 10;
65
$MinVersionSupported = 11.3;
76
If[$VersionNumber < $MinVersionSupported, Exit[$NotSupportedVersionErrNo]];
@@ -44,11 +43,15 @@ no matter the total size (tested with 80MB) *)
4443
]
4544
]
4645
},
47-
True
48-
,
46+
PacletFind["ZeroMQLink" -> "1.2*"] == {},
4947
{
5048
ZMQSocketWriteMessage,
5149
SocketReadMessage[#, "Blocking"->False] &
50+
},
51+
True,
52+
{
53+
SocketWriteMessage[##, "Blocking"->False] &,
54+
SocketReadMessage[#, "Blocking"->False] &
5255
}
5356
];
5457

@@ -185,10 +188,10 @@ no matter the total size (tested with 80MB) *)
185188
$MaxIdlePause=.001;
186189
$MinIdlePause=0.0001;
187190
$PauseIncrement=0.0001;
188-
$TaskSupportMinVersion = Infinity;
189-
191+
(*$ListenerSupportMinVersion = 12.3;*)
192+
$ListenerSupportMinVersion = Infinity;
190193
Which[
191-
$VersionNumber < $TaskSupportMinVersion,
194+
$VersionNumber < $ListenerSupportMinVersion,
192195
(* Low CPU wait but need synchronous loop. *)
193196
evaluationLoop[socketIn_SocketObject]:= With[
194197
{maxPause=$MaxIdlePause, minPause=$MinIdlePause, incr=$PauseIncrement, poller={socketIn}},
@@ -204,8 +207,20 @@ no matter the total size (tested with 80MB) *)
204207
]
205208
]
206209
],
210+
(* Version with SocketListen, code is cleaner is 3 times slower as the version above.
211+
Possibly during the async events and pre-emptive evaluation.
212+
*)
207213
True,
208-
(* Version with fixed asynchronous tasks *)
214+
evaluationLoop[socketIn_SocketObject]:= (
215+
$SocketListener = SocketListen[
216+
socketIn,
217+
socketEventHandler[#DataByteArray]&
218+
];
219+
SendAck[];
220+
Pause[2^60];
221+
);
222+
(*
223+
Version with fixed asynchronous tasks
209224
evaluationLoop[socketIn_SocketObject]:= With[
210225
{maxPause=$MaxIdlePause, minPause=$MinIdlePause, incr=$PauseIncrement, poller={socketIn}},
211226
$Task = SessionSubmit[
@@ -218,32 +233,33 @@ no matter the total size (tested with 80MB) *)
218233
SocketWaitNext[poller];
219234
]
220235
),
221-
0.0001 (*negligeable compared to IO operations ~1ms. We basically need 0 but can't use this value. *)
236+
0.0001 negligeable compared to IO operations ~1ms. We basically need 0 but can't use this value.
222237
],
223238
Method->"Idle",
224239
HandlerFunctions-><|"TaskStarted"->SendAck[]|>
225240
];
226241
];
242+
*)
227243
];
228244
(* can be useful for loopback connections which are available only if a task can be used.
229245
Does not kill the kernel *)
230246
ClientLibrary`disconnect[] := Quit[];
231-
ClientLibrary`disconnect[] /; ($Task =!= None) := (
232-
TaskRemove[$Task];
247+
ClientLibrary`disconnect[] /; ($SocketListener =!= None) := (
248+
DeleteObject[$SocketListener];
233249
Scan[
234250
If[# =!= None, Close[#]] &,
235251
{$LoggerSocket, $OutputSocket, $InputSocket}
236252
]
237253
);
238-
$Task = None;
254+
$SocketListener = None;
239255
$LoggerSocket=None;
240256
$OutputSocket=None;
241257
$InputSocket=None;
242258

243259
$MaxMessagesReturned = 31;
244260
$NoMessage = ByteArray[{0}];
245261

246-
SlaveKernelPrivateStart[inputsocket_String, outputsocket_String, logsocket_String, loglevel_Integer] := (
262+
KernelPrivateStart[inputsocket_String, outputsocket_String, logsocket_String, loglevel_Integer] := (
247263
$LoggerSocket=SocketConnect[logsocket,"ZMQ_PUB"];
248264
If[FailureQ[$LoggerSocket],
249265
Print["Failed to connect to logging socket: ", logsocket]
@@ -252,12 +268,12 @@ no matter the total size (tested with 80MB) *)
252268
setLogLevel[loglevel];
253269
addMessageHandler[];
254270
addPrintHandler[];
255-
SlaveKernelPrivateStart[inputsocket, outputsocket]
271+
KernelPrivateStart[inputsocket, outputsocket]
256272
];
257273
);
258274

259275

260-
SlaveKernelPrivateStart[inputsocket_String, outputsocket_String] := Block[
276+
KernelPrivateStart[inputsocket_String, outputsocket_String] := Block[
261277
{listener, msg},
262278
$InputSocket = SocketConnect[inputsocket, "ZMQ_Pull"];
263279
$OutputSocket = SocketConnect[outputsocket, "ZMQ_Push"];

wolframclient/evaluation/kernel/kernelcontroller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def _kernel_start(self):
392392
self.kernel_logger.start()
393393
cmd.append("-run")
394394
cmd.append(
395-
'ClientLibrary`Private`SlaveKernelPrivateStart["%s", "%s", "%s", %i];'
395+
'ClientLibrary`Private`KernelPrivateStart["%s", "%s", "%s", %i];'
396396
% (
397397
self.kernel_socket_out.uri,
398398
self.kernel_socket_in.uri,
@@ -403,7 +403,7 @@ def _kernel_start(self):
403403
else:
404404
cmd.append("-run")
405405
cmd.append(
406-
'ClientLibrary`Private`SlaveKernelPrivateStart["%s", "%s"];'
406+
'ClientLibrary`Private`KernelPrivateStart["%s", "%s"];'
407407
% (self.kernel_socket_out.uri, self.kernel_socket_in.uri)
408408
)
409409

wolframclient/tests/evaluation/test_kernel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,27 @@ def test_throw(self):
298298
class TestSessionTimeout(TestCaseSettings):
299299
def test_evaluate_async_basic_inputform(self):
300300
future = self.kernel_session.evaluate_future("1+1")
301-
self.assertEqual(future.result(timeout=1), 2)
301+
self.assertEqual(future.result(timeout=2), 2)
302302

303303
def test_evaluate_async_basic_wl(self):
304304
future = self.kernel_session.evaluate_future(wl.Plus(1, 2))
305-
self.assertEqual(future.result(timeout=1), 3)
305+
self.assertEqual(future.result(timeout=2), 3)
306306

307307
def test_evaluate_multiple_async(self):
308308
with WolframLanguageSession(kernel_path) as kernel_session:
309309
future1 = kernel_session.evaluate_future("3+4")
310310
result1 = future1.result(timeout=3)
311311
self.assertEqual(result1, 7)
312312
future2 = kernel_session.evaluate_future("10+1")
313-
self.assertEqual(future2.result(timeout=1), 11)
313+
self.assertEqual(future2.result(timeout=2), 11)
314314
future3 = kernel_session.evaluate_future("100+1")
315-
self.assertEqual(future3.result(timeout=1), 101)
315+
self.assertEqual(future3.result(timeout=2), 101)
316316

317317
def test_many_failures_wrap_async(self):
318318
future = self.kernel_session.evaluate_wrap_future(
319319
'ImportString["[1,2", "RawJSON"]; 1/0'
320320
)
321-
res = future.result(timeout=1)
321+
res = future.result(timeout=2)
322322
self.assertFalse(res.success)
323323
expected_msgs = (
324324
"Expecting end of array or a value separator.",
@@ -342,7 +342,7 @@ def test_many_failures_wrap_async(self):
342342

343343
def test_valid_evaluate_wxf_async(self):
344344
future = self.kernel_session.evaluate_wxf_future("Range[3]")
345-
wxf = future.result(timeout=1)
345+
wxf = future.result(timeout=2)
346346
result = binary_deserialize(wxf, consumer=WXFConsumer())
347347
self.assertEqual(result, [1, 2, 3])
348348

0 commit comments

Comments
 (0)