Group commands to run in background
kumarappan-arumugam opened this issue · comments
Kumarappan Arumugam commented
Is there a way to call a group of commands to execute in the background like a sub-shell?
For example:
@sh(_bg=True)
def build():
sh.rm('something')
try:
sh.yarn.build() # long running process
except:
sh.yarn.build_without_cache() # long running process
sh.mkdir('something')
sh.find('something')
procs = []
for dir in all_dirs:
procs.append(build()) # parallel
[p.wait() for p in procs]
I know I can manually fork another child process, but was trying to figure out if I can do something with the existing functions in the sh.py
.
Andrew commented
There isn't, no. It is an interesting idea, but to do what your code snippet suggests would require implementing some kind of process-coordinator that is outside of the scope of sh.