Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error emitted on keyboard interrupt #406

Open
seanders opened this issue Mar 24, 2024 · 1 comment
Open

Error emitted on keyboard interrupt #406

seanders opened this issue Mar 24, 2024 · 1 comment

Comments

@seanders
Copy link

Hi there,

I'm seeing this error stacktrace when killing a lumibot process via the keyboard interrupt.

^C2024-03-22 22:40:13,741: asyncio: INFO: [MyStrategy] Executing the on_abrupt_closing event method
Breaking loop because should not continue.
Traceback (most recent call last):
  File "/Users/sean/workspace/trading_bot_test/./executeStrategies.py", line 43, in <module>
    trader.run_all()
  File "/usr/local/lib/python3.11/site-packages/lumibot/traders/trader.py", line 117, in run_all
    self._join_pool()
  File "/usr/local/lib/python3.11/site-packages/lumibot/traders/trader.py", line 197, in _join_pool
    strategy_thread.join()
  File "/usr/local/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 245, in join
    super(StrategyExecutor, self).join(timeout)
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1112, in join
    self._wait_for_tstate_lock()
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1132, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/lumibot/traders/trader.py", line 207, in _stop_pool
    strategy_thread.stop()
  File "/usr/local/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 242, in stop
    self._on_abrupt_closing(KeyboardInterrupt())
  File "/usr/local/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 438, in _on_abrupt_closing
    self.strategy._dump_stats()
  File "/usr/local/lib/python3.11/site-packages/lumibot/strategies/_strategy.py", line 572, in _dump_stats
    if self._backtesting_start is not None and self._backtesting_end is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MyStrategy' object has no attribute '_backtesting_start'. Did you mean: 'backtesting_start'?
@jimwhite
Copy link
Collaborator

Are you backtesting the strategy or live/paper trading? If backtesting did you set a start time one way or another? It looks to me as though _Strategy._dump_stats will fail this way when not backtesting because _backtesting_start is only set when _is_backtesting is True.

jimwhite added a commit that referenced this issue May 18, 2024
Fix Issue #406 which is due to trying to access _backtesting_start when not backtesting.

Also move that big chunk of code into its own method so we can see what's going on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants