| Conditions | 4 |
| Total Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | # encoding: utf-8 |
||
| 12 | def p_map(pool, function, data): |
||
| 13 | """replacement for Pool.map from multiprocessing. |
||
| 14 | The ability to pickle objects using the Python pickle / cPickle module |
||
| 15 | limits the functions and data you can process with Pool.map. |
||
| 16 | |||
| 17 | Here we use dill instead, which eg can pickle instance methods. |
||
| 18 | |||
| 19 | Inspired by |
||
| 20 | https://stackoverflow.com/questions/8804830/python-multiprocessing-pickling-error/24673524#24673524 |
||
| 21 | """ |
||
| 22 | |||
| 23 | assert isinstance(data, (list, tuple, set)) |
||
| 24 | payload = [dill.dumps((function, args)) for args in data] |
||
| 25 | results = pool.map(execute, payload) |
||
| 26 | return [dill.loads(result) for result in results] |
||
| 27 |