0

I'm trying to execute multiple linux commands using Python. Currently my script is

    import os
    os.system('cmd1')
    os.system('cmd2')
    os.system('cmd3')
    os.system('cmd4')

I'm wondering if there's a way to execute cmd1 and cmd2 in parallel. After cmd1 and cmd2 finishes, the system will execute cmd3 and cmd4? Thanks!

3
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. on topic and how to ask apply here. StackOverflow is not a design, coding, research, or tutorial service. Commented Jul 28, 2017 at 21:30
  • 1
    More to the point, your browser search should have given you a hit for the multiprocessing package. Commented Jul 28, 2017 at 21:31
  • Actually, subprocess should also work and be enough to spawn them in parallel. See this answer: stackoverflow.com/questions/9743838/… Commented Jul 28, 2017 at 21:39

1 Answer 1

0

Use os.fork() and run the two system commands in two children. Use os.waitpid() on the two children before executing cmd3.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.