Easy Parallelism and Currying in Python – POST 10 HTTP requests, 5 threads maximum


Sometimes the curl|xargs version is not adequate.

#!/usr/bin/env python2

import functools, urllib, multiprocessing

def postToHost(host, tid):
    print host, "id=%d" % (tid)
    urllib.urlopen(host, "id=%d" % (tid)).read(()

pool = multiprocessing.Pool(5)
postToHostFunc = functools.partial(postToHost, "http://te.st")
pool.map(postToHostFunc, xrange(1, 11))