|
@@ -162,8 +162,8 @@ class BotManager:
|
|
|
except Exception as e:
|
|
|
self.logger.error(f"❌ Bot error in BotManager.run_bot: {e}", exc_info=True)
|
|
|
# Ensure cleanup is attempted
|
|
|
- if self.bot and self.bot.application and self.bot.application.is_running:
|
|
|
- logger.info("Attempting to stop application due to error in run_bot...")
|
|
|
+ if self.bot and self.bot.application and self.bot.application._running:
|
|
|
+ self.logger.info("Attempting to stop application due to error in run_bot...")
|
|
|
await self.bot.application.stop()
|
|
|
raise # Re-raise the exception to be caught by main()
|
|
|
|
|
@@ -200,18 +200,18 @@ def main():
|
|
|
success = asyncio.run(bot_manager.start())
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
- logger.info("👋 Bot stopped by user (Ctrl+C in main).")
|
|
|
+ logging.getLogger(__name__).info("👋 Bot stopped by user (Ctrl+C in main).")
|
|
|
print("\n👋 Bot stopped by user.")
|
|
|
except Exception as e:
|
|
|
- logger.critical(f"💥 Unexpected critical error in main: {e}", exc_info=True)
|
|
|
+ logging.getLogger(__name__).critical(f"💥 Unexpected critical error in main: {e}", exc_info=True)
|
|
|
print(f"\n💥 Unexpected critical error: {e}")
|
|
|
finally:
|
|
|
- logger.info("BotManager main function finished.")
|
|
|
+ logging.getLogger(__name__).info("BotManager main function finished.")
|
|
|
print("📊 Your trading statistics should have been saved by the bot's internal shutdown.")
|
|
|
|
|
|
if bot_manager and bot_manager.bot and bot_manager.bot.application:
|
|
|
- if bot_manager.bot.application.is_running:
|
|
|
- logger.warning("Application was still marked as running in main finally block. Attempting forced synchronous stop. This may not work if loop is closed.")
|
|
|
+ if hasattr(bot_manager.bot.application, '_running') and bot_manager.bot.application._running:
|
|
|
+ logging.getLogger(__name__).warning("Application was still marked as running in main finally block. Attempting forced synchronous stop. This may not work if loop is closed.")
|
|
|
|
|
|
if not success:
|
|
|
print("\n❌ Bot session ended with errors.")
|