I want to improve performance by moving the heavy processing of daily bars and indicator generation outside the on_data method. The plan is to simply collect the data slice within on_data, then schedule a separate event to handle the intensive processing one minute after market close.

However, I'm concerned about the timing: if process_daily_bars takes a long time to complete, and on_data proceeds to the next trading day in the meantime, it may cause daily_bars to be overwritten or emptied before process_daily_bars finishes.

Could you please confirm whether the scheduled after-market event and the on_data method are able to safely handle different dates in parallel, especially when one of them runs significantly slower?  Example of the code   

 def on_data(self, data):
        """Cache daily bars and update VIX values."""
        if self.vix in data:
            vix_bar = data[self.vix]
            if isinstance(vix_bar, TradeBar):
                self.current_vix = vix_bar.Close
            else:
                self.current_vix = getattr(vix_bar, 'Value', np.nan)

        for symbol, bar in data.Bars.items():
            if symbol in self.symbol_data:
                self.daily_bars[symbol] = bar
 def process_daily_bars(self):
        """Process cached daily bars after market close."""
        if self.IsWarmingUp or not self.daily_bars:
            return
        self._process_slice(self.daily_bars)
        self.daily_bars = {}
 # Process daily bars and indicators after market close
        self.Schedule.On(
            self.DateRules.EveryDay(),
            self.TimeRules.AfterMarketClose("SPY", 1),
            self.process_daily_bars
        )