Threading Error in cerebro.run(maxcpus=...)
-
Successfully ran the strategy selection code in https://www.backtrader.com/blog/posts/2016-10-29-strategy-selection/strategy-selection/ (regardless of the value assigned to
maxcpus
).So, I extended the code to my needs.
In my code, when
maxcpus
parameter incerebro.run(maxcpus = ...)
is greater than 1, the error shown below would occur (it's a threading error). No errors occur whenmaxcpus = 1
and the run completes smoothly.Any idea as to what I should look at to find the source of the error?
Changing the value of
optreturn
incerebro.run(..)
has no effect on this error.Should I change to another version of pickling/pickler?
> python stratsel.py Starting Portfolio Value: 1000.00 Exception in thread Thread-3: Traceback (most recent call last): File "/Users/d/opt/anaconda3/envs/myenv/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/Users/d/opt/anaconda3/envs/myenv/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/Users/d/opt/anaconda3/envs/myenv/lib/python3.7/multiprocessing/pool.py", line 470, in _handle_results task = get() File "/Users/d/opt/anaconda3/envs/myenv/lib/python3.7/multiprocessing/connection.py", line 251, in recv return _ForkingPickler.loads(buf.getbuffer()) AttributeError: Can't get attribute 'Lines_LineSeries_LineIterator_DataAccessor_ObserverBase_Observer_DataTrades_7a5dc4c5b1604837b6655d447e5ae1e0' on <module 'backtrader.lineseries' from '/Users/d/opt/anaconda3/envs/myenv/lib/python3.7/site-packages/backtrader/lineseries.py'>
-
Please try to set the
stdstats
parameter toFalse
:bt.Cerebro(maxcpus = ..., stdstats = False))
This will disable the standard observers that are automatically added to your strategy by default. More here
Also see the following posts:
https://community.backtrader.com/topic/1252/optimization-error-when-multiple-data-feed/3
https://community.backtrader.com/topic/2265/exception-when-running-optimize-with-optreturn-false/6 -
@vladisld Thank you. Yes, the solution proposed resolved the error. I guess those facing this issue will have to manually add the observers they desire.