Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Threading Error in cerebro.run(maxcpus=...)

    General Code/Help
    2
    3
    362
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LisaWalters last edited by

      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 in cerebro.run(maxcpus = ...) is greater than 1, the error shown below would occur (it's a threading error). No errors occur when maxcpus = 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 in cerebro.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'>
      
      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Please try to set the stdstats parameter to False:

        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

        L 1 Reply Last reply Reply Quote 3
        • L
          LisaWalters @vladisld last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors