Child background Julia processes from R Shiny apps do not stay alive after app is closed

Viewed 95

I need to spawn an independent background Julia process from a shiny app that survives once the app is closed.

If the Julia process is called inline: sys::exec_background('nohup', c("julia", "-e sleep(3000)", "&") the child process survives the Shiny app once it get closed.

But if the Julia process is called on a script with just the same sleep(3000) call inside: sys::exec_background('nohup', c("julia", "test.jl", "&") once the Shiny app closes also the Julia process gets killed with error:

signal (2): Interrupt: 2
in expression starting at .../test.jl:1

kevent at /usr/lib/system/libsystem_kernel.dylib (unknown line)
unknown function (ip: 0x0)
Allocations: 2650 (Pool: 2641; Big: 9); GC: 0

Any idea why and any solution on how to have the Julia script process survive the parent app?

Here's the code to reproduce the behaviour. https://gist.github.com/bakaburg1/5d1b5135fb3b4db1a3ca2eb7e8639aa5 Just run the Shiny app and then close it. Only the inline code Julia process survives.

1 Answers

There are Unix tools such a nohup and & to detach the forked and process and have it alive without their parent.

This works on my machine and should work on yours:

system("bash -c \"nohup julia -e \\\"println(1);sleep(1000);println(2)\\\" &\"")

Depending on platform you might be able to skip bash -c and just have:

system("nohup julia -e \"println(1);sleep(1000);println(2)\" &")
Related