WolframWebEngineForPython icon indicating copy to clipboard operation
WolframWebEngineForPython copied to clipboard

Issue when using Wolfram WebEngine Py for generating documents

Open s4m13337 opened this issue 1 year ago • 0 comments

PS: I'm posting this on behalf of Jörg Schönau at Additive GmbH

We observed an issune when using WEPy for generating documents. It should be easy to reproduce following this steps:

  1. Create an initialization code file with the following content and name it myinit.m:
ReportFunction[x_]:=Module[
     {nbobj, res},
     Print["myinit.m | ReportFunction | function started"];
     Print["x: "Head[x], "  x: ", InputForm[x]];
     UsingFrontEnd[
         Print["myinit.m | ReportFunction | after UsingFrontEnd", x];
         nbobj = GenerateDocument["ExampleData/BasicTemplate.nb", x];
         Print["myinit.m | ReportFunction | nbobj created: ", nbobj];
         res = ExportString[nbobj, "HTML"];
         Print["myinit.m | ReportFunction | res created: ", 
StringLength[res]];
         NotebookClose[nbobj];
         Print["myinit.m | ReportFunction | nbobj closed."];
         Return[res]
     ]
]
  1. Change the content of testapp/form/index.wl to:
FormFunction["author" -> "String", ReportFunction]
  1. Now launch the WEPy like this:
py -3.11 -m wolframwebengine testapp --initfile myinit.m
  1. Finally call that page in a browser http://localhost:18000/form

Now you can put any string into that form and [ubmit That page will run forever and the log file of WEPy says:

Kernel writes commands to socket: <Socket: uri=tcp://127.0.0.1:50973>
Kernel receives evaluated expressions from socket: <Socket: 
uri=tcp://127.0.0.1:50974>
Initializing Kernel logger on socket tcp://127.0.0.1:50977
Kernel process started with PID: 8
Connected to logging socket: tcp://127.0.0.1:50977
Kernel 8 is ready. Startup took 4.61 seconds.
GET /form done in 0.8590s: 200
192.168.98.200 - Administrator [26/Mar/2024:10:38:04 +0100] "myinit.m | 
ReportFunction | function started" 1 8
"x: "*Association   x:  InputForm[<|"author" -> "Otto Meier"|>]
192.168.98.200 - Administrator [26/Mar/2024:10:38:06 +0100] "myinit.m | 
ReportFunction | after UsingFrontEnd <|author -> Otto Meier|>" 1 8

So the evaluation stops after the Mathematica.exe has successfully launched. The GenerateDocument command never evaluates... WolframKernel.exe and Mathematica.exe stay in the list of processes but will not get stopped when stopping the WEPy script.

s4m13337 avatar Dec 10 '24 08:12 s4m13337