For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

# Exception when running optimize with optreturn=False

• I am experiencing crashes when trying to run an optimization. I reduced it to quite a simple test case to reproduce the error:

``````import datetime

class TestStrategy(bt.Strategy):
params = (
('period', 15),
('printdata', True),
('printops', True),
)

if __name__ == '__main__':
cerebro = bt.Cerebro(maxcpus=0, optreturn=False)

cerebro.optstrategy(TestStrategy, period=[5, 6, 7])

data = bt.feeds.YahooFinanceCSVData(
dataname=r"..\datas\nvda-1999-2014.txt",
fromdate=datetime.datetime(2000, 1, 1),
todate=datetime.datetime(2002, 12, 31),
reverse=False,
swapcloses=True,
)

data = bt.feeds.YahooFinanceCSVData(
dataname=r"..\datas\orcl-1995-2014.txt",
fromdate=datetime.datetime(2000, 1, 1),
todate=datetime.datetime(2002, 12, 31),
reverse=False,
swapcloses=True,
)

cerebro.run()
``````

This is the result:

``````(qrawler) C:\Users\Robin\Projects\backtrader\tests>python test_multidata_optimize.py
Traceback (most recent call last):
File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\multiprocessing\pool.py", line 463, in _handle_results
File "C:\Users\Robin\Miniconda3\envs\qrawler\lib\multiprocessing\connection.py", line 251, in recv
``````

My Python:

``````(qrawler) C:\Users\Robin\Projects\backtrader\tests>python -V
Python 3.6.9 :: Anaconda, Inc.
``````

Any idea whats wrong on my end or actually backtrader's fault?

• Disable the observers with `stdstats=False`

• Thank you, yes I know, but then all observers are gone :)

• I think I fixed it. Seems to work with the observers.

});