Skip to content

Commit 0477879

Browse files
committed
Add --startuptimeout CLI option to adjust WolframClientForPython kernel startup timeout
1 parent 21b3504 commit 0477879

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ optional arguments:
193193
--domain DOMAIN Insert the domain.
194194
--kernel KERNEL Insert the kernel path.
195195
--poolsize POOLSIZE Insert the kernel pool size.
196+
--startuptimeout SECONDS
197+
Startup timeout (in seconds) for kernels in the pool.
196198
--cached The server will cache the WL input expression.
197199
--lazy The server will start the kernels on the first
198200
request.
@@ -320,6 +322,24 @@ Index index.wl
320322
(Press CTRL+C to quit)
321323
```
322324

325+
#### --startuptimeout SECONDS
326+
327+
By default, an attempt to start a kernel will be aborted if the kernel is not ready after 20 seconds. If your application contains long-running initialization code, you may need to raise this timeout.
328+
```
329+
>>> python3 -m wolframwebengine
330+
(...)
331+
Kernel process started with PID: 485
332+
Socket exception: Failed to read any message from socket tcp://127.0.0.1:5106 after 20.0 seconds and 245 retries.
333+
Failed to start.
334+
335+
336+
>>> python3 -m wolframwebengine --startuptimeout 50
337+
(...)
338+
Kernel process started with PID: 511
339+
Connected to logging socket: tcp://127.0.0.1:5447
340+
Kernel 511 is ready. Startup took 35.43 seconds.
341+
```
342+
323343
#### --lazy
324344

325345
If the option is present the server will wait for the first request to spawn the kernels, instead of spawning them immediately.

wolframwebengine/cli/commands/runserver.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def add_arguments(self, parser):
4141
parser.add_argument(
4242
"--poolsize", default=1, help="Insert the kernel pool size.", type=int
4343
)
44+
parser.add_argument(
45+
"--startuptimeout",
46+
default=20,
47+
help="Startup timeout (in seconds) for kernels in the pool.",
48+
type=int,
49+
metavar="SECONDS"
50+
)
4451
parser.add_argument(
4552
"--cached",
4653
default=False,
@@ -88,15 +95,21 @@ def demo_choices(self):
8895
def demo_path(self, *args):
8996
return module_path("wolframwebengine", "examples", "demo", *args)
9097

91-
def handle(self, domain, port, path, kernel, poolsize, lazy, index, demo, **opts):
98+
def handle(self,
99+
domain, port, path, kernel, poolsize, startuptimeout,
100+
lazy, index, demo, **opts
101+
):
92102

93103
if demo is None or demo:
94104
path = self.demo_path(self.demo_choices[demo])
95105

96106
path = os.path.abspath(os.path.expanduser(path))
97107

98108
try:
99-
session = create_session(kernel, poolsize=poolsize)
109+
session = create_session(kernel,
110+
poolsize=poolsize,
111+
STARTUP_TIMEOUT=startuptimeout
112+
)
100113

101114
except WolframKernelException as e:
102115
self.print(e)

0 commit comments

Comments
 (0)