davecliff/BristolStockExchange — pull request #12 by AWhetter (2014-12-11 13:07:51+00:00)
Title: Parallel execution

This pull request implements the running of the stock exchange in multiple threads. By default it will run with as many threads as there are cores on the machine.

This is tested as working in Python v2.7.8 and on the lab machines (Python v2.6.6).

The largest change this pull request makes is how the combinations of traders are generated. Instead of using nested while loops itertools.product generates all possible permutations of traders, then itertools.ifilter fillters this list to only those permutations with the correct number of traders in the market.
This has the nice side effect of making it easier to add new types of trader. To add a new trader an entry needs to be added to the trader_types dictionary, and the itertools generators will include it in the permutations of traders.

The only quirk with this pull request is that I've commented out the line that writes the transactions.csv file because with more than one thread, every thread tries to open the file and write to it at once.