(processes=None, initializer=None, initargs=())
| 72 | |
| 73 | # Add overridable backtesting.Pool used for parallel optimization |
| 74 | def Pool(processes=None, initializer=None, initargs=()): |
| 75 | import multiprocessing as mp |
| 76 | if mp.get_start_method() == 'spawn': |
| 77 | import warnings |
| 78 | warnings.warn( |
| 79 | "If you want to use multi-process optimization with " |
| 80 | "`multiprocessing.get_start_method() == 'spawn'` (e.g. on Windows)," |
| 81 | "set `backtesting.Pool = multiprocessing.Pool` (or of the desired context) " |
| 82 | "and hide `bt.optimize()` call behind a `if __name__ == '__main__'` guard. " |
| 83 | "Currently using thread-based paralellism, " |
| 84 | "which might be slightly slower for non-numpy / non-GIL-releasing code. " |
| 85 | "See https://github.com/kernc/backtesting.py/issues/1256", |
| 86 | category=RuntimeWarning, stacklevel=3) |
| 87 | from multiprocessing.dummy import Pool |
| 88 | return Pool(processes, initializer, initargs) |
| 89 | else: |
| 90 | return mp.Pool(processes, initializer, initargs) |
no outgoing calls