Skip to content

Instantly share code, notes, and snippets.

@tatic0
Created December 29, 2016 16:02
Show Gist options
  • Save tatic0/51012c9edb66742ee1435ea6f4b9e9a7 to your computer and use it in GitHub Desktop.
Save tatic0/51012c9edb66742ee1435ea6f4b9e9a7 to your computer and use it in GitHub Desktop.
Python thread + subprocess example
# it will calculate the md5sum of
# all files in the arborescence
from threading import Thread
import subprocess
import os
def slowthing(i):
cmd = ["md5sum", i]
print(cmd)
subprocess.call(cmd)
for i,j,k in os.walk("."):
for l in k:
each = os.path.join(i,l)
t = Thread(target=slowthing, args=(each,))
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment