fruitJuice
fruitJuice

Reputation: 1241

python fabric, how not to parallelize local commands?

How do I NOT parallelize local commands inside a task with @parallel decorator:

@parallel
def myTask():
  local('initialize localhost')
  run('command on remote host')
  local('clean up localhost')

I want commands on local host only to execute once, and commands for remote hosts run in parallel. Right now I'm seeing local host commands running for each remote host instance. What is the cleanest way to do this?

Thanks

Upvotes: 1

Views: 621

Answers (2)

Morgan
Morgan

Reputation: 4131

Group your parallel commands into a decorated function. Then use execute() to call it inbetween the local calls.

Upvotes: 1

user650654
user650654

Reputation: 6128

Does the following work for you?

def local_init():
    local('initialize')

@parallel
def myTask():
    run('remote command')

def local_cleanup():
    local('clean up')

And then:

fab local_init myTask local_cleanup

Upvotes: 1

Related Questions