I'm trying to create multiple files which will be analyzed with a stand-alone program as part of a high throughput analysis written in python.

```
for foo in X:
    write foo_file
    os.system(run_program foo_file)

```

For 15,000 distinct individual files this will run faster if I can run them on multiple cores, but I don't want to swamp my server. How do I set up multiple threads for to run in os but put a maximum on the number of threads open at once? I'm not worried about speed of spawning processes as the runtime is defined by an external program standard in my field. 

I've looked at documentation for threading and multiprocessing and gotten overwhelmed.