Search code examples
pythonparallel-processingfabric

Running 2 tasks at the same time using Fabric


For my automation purposes, I'm using Fabric. But I could not run 2 tasks at the same time? For example, I want to run task 1 to collect data in the tmp folder. I want to run task 2 which will generate data and put in tmp. Tas1 2 will be running a bit before task 2.

Here is my sudo code:

output1 = run("./task1_data_logger &")
output2 = run("./task2_main_program")

RESULT: Task2_main_program is running fine but I didn't see task1_data_logger running at all. I thought I put the & so that Task1 can be run in the background.

I've read Parallel execution document but it is more for running parallel in multiple host, which is not my case. Anyone knows how to 2 tasks simultaneously instead of serially?

Thank you.


Solution

  • The task1 did not run at all because running a command with & in Fabric does not work. It is because, in linux when you log out of a session all the processes associated with it are terminated.

    So if you want to make sure a command keeps running even after you log out of the session you need to run it like this:

    run('nohup sh command &')