Python Script Halting in Railway

I have a Python script that is supposed to run forever, but I have seen it halt without any bugs or any other log output. My restart policy is "Always" This is the relevant part of the script
if __name__ == "__main__":
args = parser.parse_args()

bot_name = args.bot
if bot_name not in BOT_FUNCTION_MAPPING:
logger.info(f"Invalid bot name {bot_name}")
raise ValueError(f"Invalid bot name {bot_name}")

network.connect(available_networks[current_network_index])
logger.info(f"connected {network.show_active()}")

logger.info(f"Starting {bot_name}...")
infinite_loop(BOT_FUNCTION_MAPPING[bot_name])(environment)
logger.info(f"Exiting {bot_name}...")
raise SystemExit(1) # Doing this so the process can be restarted by Railway
if __name__ == "__main__":
args = parser.parse_args()

bot_name = args.bot
if bot_name not in BOT_FUNCTION_MAPPING:
logger.info(f"Invalid bot name {bot_name}")
raise ValueError(f"Invalid bot name {bot_name}")

network.connect(available_networks[current_network_index])
logger.info(f"connected {network.show_active()}")

logger.info(f"Starting {bot_name}...")
infinite_loop(BOT_FUNCTION_MAPPING[bot_name])(environment)
logger.info(f"Exiting {bot_name}...")
raise SystemExit(1) # Doing this so the process can be restarted by Railway
3 Replies
Percy
Percy14mo ago
Project ID: 42cb5f33-ac30-472f-be18-06847d544555
Heisenberg | Buffer Finance
42cb5f33-ac30-472f-be18-06847d544555
Floris
Floris14mo ago
Its usually standard to not have your if name == main not handle any logic but wrap your entry functions in a def main() can you share the infinite_loop function you have? It seems like your actually wanting to restart the python file all together but if you want it ran forever, it's better to initiate an event loop and have that run indefinitely
Want results from more Discord servers?
Add your server