The test seem to run without errors. It now yields to other processes.
This commit is contained in:
parent
4072a9d5f5
commit
fe1e93c24b
|
|
@ -3,6 +3,7 @@
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
import eventlet
|
||||||
|
|
||||||
import backtrader as bt
|
import backtrader as bt
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
@ -432,7 +433,7 @@ class Backtester:
|
||||||
backtest_key, failure_results)
|
backtest_key, failure_results)
|
||||||
|
|
||||||
# Start the backtest as a background task
|
# Start the backtest as a background task
|
||||||
self.socketio.start_background_task(execute_backtest)
|
eventlet.spawn(execute_backtest)
|
||||||
|
|
||||||
def handle_backtest_message(self, user_id: str, msg_data: dict, socket_conn_id: str) -> dict:
|
def handle_backtest_message(self, user_id: str, msg_data: dict, socket_conn_id: str) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
import backtrader as bt
|
import backtrader as bt
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
import eventlet
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from backtest_strategy_instance import BacktestStrategyInstance # Ensure correct import path
|
from backtest_strategy_instance import BacktestStrategyInstance # Ensure correct import path
|
||||||
|
|
@ -117,6 +119,8 @@ class MappedStrategy(bt.Strategy):
|
||||||
# Update progress
|
# Update progress
|
||||||
if self.p.data_length:
|
if self.p.data_length:
|
||||||
self.update_progress()
|
self.update_progress()
|
||||||
|
# Periodically yield to eventlet
|
||||||
|
eventlet.sleep(0)
|
||||||
|
|
||||||
def execute_strategy(self):
|
def execute_strategy(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -139,4 +143,5 @@ class MappedStrategy(bt.Strategy):
|
||||||
{'reply': 'progress', 'data': {'progress': progress}},
|
{'reply': 'progress', 'data': {'progress': progress}},
|
||||||
room=self.p.socket_conn_id
|
room=self.p.socket_conn_id
|
||||||
)
|
)
|
||||||
|
logger.debug(f"Emitted progress: {progress}%")
|
||||||
self.last_progress = progress
|
self.last_progress = progress
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue