Skip to content

Instantly share code, notes, and snippets.

@albertyw
Created March 23, 2018 08:19
Show Gist options
  • Save albertyw/fb79f633a6f6991b620334ded1ce7dd2 to your computer and use it in GitHub Desktop.
Save albertyw/fb79f633a6f6991b620334ded1ce7dd2 to your computer and use it in GitHub Desktop.

Revisions

  1. albertyw created this gist Mar 23, 2018.
    23 changes: 23 additions & 0 deletions process.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import subprocess
    import time


    commands = ['./time.sh'] * 5
    outputs = [None] * len(commands)
    processes = [None] * len(commands)


    start = time.time()


    for i, command in enumerate(commands):
    process = subprocess.Popen([command], stdout=subprocess.PIPE)
    processes[i] = process


    for i, process in enumerate(processes):
    outputs[i] = process.communicate()
    print(i, outputs[i])


    print('elapsed seconds: ', time.time() - start)
    3 changes: 3 additions & 0 deletions time.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash
    sleep 2
    date