Execute Fabric functions in parallel and in the background on different hosts

Similar questions have already been asked, but have not resolved my case.

I have something like:

from fabric.api import *
env.rolesdefs = {'server1' : [me@312312], 'server2' : [me@978978]}

@roles('server1')
def run_task1():
    do_stuff_forever

@roles('server2')
def run_task2():
    do_other_stuff_forever        

      

Since the behavior is * _forever, I cannot serially run them. task2 on server2 will never start. How can I run them at the same time in parallel on two different servers? I tried:

def run_all():
    execute(run_task1)
    execute(run_task2)

      

The @parallel decorator didn't work. I've tried the suggestions given here Thorough FAQ . With only a screen available, I couldn't figure out how to start two screen sessions at the same time. I thought running the first one in the background might solve my problem? How would I put task1 in the background securely? Running cloth 1.4 and pytho n2.6

Thanks for the help.

PS: I want to avoid the obvious hack with a shell script doing both tasks separately in bkg:

#! /bin/bash
fab run_task1 &
fab run_task2 &

      

+3


source to share


1 answer


What to do if you installed

env.parallel = True

      



Does it help?

-2


source







All Articles