Here is a working code that utilizes multiprocessing and subprocess's popen() to copy files from source to destination.
import os, sys, subprocess
from multiprocessing import Pool
def copyUsingSubprocess(source):
folder=os.path.dirname(source)
srcFileName, srcFileExt=os.path.splitext(os.path.basename(source))
destFilename=srcFileName+'_dest'+srcFileExt
dest='/'.join([folder,destFilename])
cmd=['cp', source, dest]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sources = ['/Volumes/files/a.data','/Volumes/files/b.data',
'/Volumes/files/c.data','/Volumes/files/d.data',
'/Volumes/files/e.data','/Volumes/files/f.data']
pool = Pool(20)
results = pool.map(copyUsingSubprocess, sources)
The one below is a similar code. It does use a subprocess.popen() to perform file copying too. But it does it without calling a multiprocessing's Pool.map() method.
import os, sys, subprocess
def copyUsingSubprocess(cmd):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sources = ['/Volumes/files/a.data','/Volumes/files/b.data',
'/Volumes/files/c.data','/Volumes/files/d.data',
'/Volumes/files/e.data','/Volumes/files/f.data']
for source in sources:
folder=os.path.dirname(source)
srcFileName, srcFileExt=os.path.splitext(os.path.basename(source))
destFilename=srcFileName+'_dest'+srcFileExt
dest='/'.join([folder,destFilename])
cmd=['cp', source, dest]
copyUsingSubprocess(cmd)