Background job execution
jurafa opened this issue · 3 comments
I would like to be able to execute a command in shell asynchronously and do not wait for the result in the sense of 'fire and forget'.
The reason for this is that the command might take very long time to finish and I want the request sent to the openresty to be finished without waiting for it.
I was trying to use background jobs with '&' operator but without success.
prog.argv = {'bash', '-c', 'sleep 10 &'}
The command gets executed alright but the program still waits for the command to finish.
Would it be possible to add the feature of executing the command in the background?
@jurafa I would check out using start-stop-daemon
, for example:
local res, err = prog('start-stop-daemon','--pidfile','/dev/null','--background','--exec','/usr/bin/sleep', '--start','--','10')
does what you intend - it will cause sleep 10
to run in the background and the call to prog
returns immediately. That also lets you get around sockexec
's built-in timeouts, etc, since it runs entirely detached.
Alternatively, I went ahead and wrote a small program for spawning programs off into the background: https://github.com/jprjr/idgaf - I have static binaries available to download.
This would allow you to use something like:
prog.argv = {'bash', '-c', 'idgaf sleep 10'}
Using start-stop-daemon was the way to go for me. Thanks. :-)