Hi there,
is there a way to quit sclang
automatically when the scsynth
server process exits? This should happen anytime the server process quits, regardless of what caused its termination, specifically I want to also cover the case where the server’s exit was not triggered by the interpreter.
Use case:
some audio backends (namely Jack and Bela) can cause the server to quit, however the sclang
process will keep running, which is unwanted in a headless situation. By having sclang
monitor the scsynth
process it started, the sclang
process can quit as expected.
Hey Giuliomoro, I think you’re looking for ServerQuit
? https://doc.sccode.org/Classes/ServerQuit.html
This should do it: ServerQuit.add({ 0.exit })
Great, that seems to work, thanks a lot! Is there a way to also get the server’s exist status so that it can be passed on as the exist status of sclang
?
On a related note, do you think it would be useful to the wider community to allow to pass a command line option to sclang
that would do the equivalent of this line? I am thinking that this way one would not need to add that to each of the files used for headless operation, they woudl just need to start sclang
with the additional command-line option. On the other hand, writing .scd
files the way it is required for headless use (with most code written inside a s.waitForBoot
clause) may not be how most people would want to do their regular development anyhow …
unfortunately you can’t get the exit code this way, and i would consider that a defect. the exit code of the server is discarded before it makes it to user callbacks. you could instead run a wait
(the linux/bash command) on the pid of the server process, which is stored on the server once it’s booted, and exit with whatever exit code wait
gives you.
sclang exit behavior is complicated and we have other tickets / discussions open about it. adding a new cli flag for one specific case without addressing that larger design problem would be the wrong thing to do. however, i think making that behavior more configurable would benefit everyone.
It’s currently possible to hack the boot process like this:
Server.default = s = Server.remote(\newLocal, NetAddr("127.0.0.1", 57110), Server.default.options);
s.startAliveThread;
("scsynth" + s.options.asOptionsString).unixCmd({ |exitcode, pid| exitcode.debug("exited with") });
… and the process-completion function passed to unixCmd does get the exit code.
(I had thought that perhaps the internal server might take down sclang upon an exception, but I tested it and found that the sclang process properly handles exceptions thrown by the internal server! So, cheers for good engineering )
I completely agree with Brian that we should pass the exit code through to ServerQuit functions. My suggestion here is a hack/workaround, not a proper solution
hjh
I see what you are doing there … but I guess I’ll stick to the supported method for now
thanks both