I have a large codebase in which some functions make calls to Python TCP servers. The code used to work perfectly in Mathematica 12.2
, but has not worked since I updated to Mathematica 12.3
last night.
I have managed to isolate the problem to the call to WriteString
. The following is a minimum illustration of the issue. Here is the Python server:
import socketserver
import json
import time
class TCPHandler(socketserver.BaseRequestHandler):
def handle(self):
bufSz = 2048
while True:
self.data = self.request.recv(bufSz)
if self.data:
jsonReq = json.loads(self.data.strip())
print(f"Request: {jsonReq}")
jsonRes = json.dumps({"res": len(jsonReq["arg"])})
print(f"Response: {jsonRes}")
self.request.sendall(bytes(jsonRes, "utf-8"))
else:
time.sleep(0.10)
self.data = ""
continue
def main():
host, port = "localhost", 9990
with socketserver.TCPServer((host, port), TCPHandler) as server:
print(f"Test server now running at {host} on port {port}")
server.serve_forever()
if __name__ == "__main__":
main()
And here is the Wolfram Language
code that calls it:
ClearAll[sock];
sock = SocketConnect[{"localhost", 9990}, "TCP"];
ClearAll[params];
params = ExportString[<|"arg" -> "test string"|>, "JSON"];
Module[{res},
WriteString[sock, params];
res = ByteArrayToString@SocketReadMessage[sock];
ImportString[res, "JSON"]
]
This exact set-up used to work for me reliably until Mathematica 12.2
. But now the execution hangs at the WriteString
command.
I have tried turning off Windows firewall entirely. The problem persists.
Any assistance would be gratefully acknowledged.
Wolfram Research
will at least provide a workaround soon. This represents a huge problem for me. $\endgroup$