I have a stock market bot that I wrote in python and I used the keep_alive system to run this bot 24/7.
from flask import Flask
from threading import Thread
app = Flask('')
return "I'm alive"
t = Thread(target=run)
my code works 24/7 but it closes itself causing me a big problem
the stops here all happen on their own.
How can I solve this problem?
- Basically, Replit force shuts down Repls to save resources. Think about it, if you had your computer running a program forever, never stopping, running with essentially infinite resources, even when it’s not doing anything. That’s basically most Repls. Which is why Replit will shut down Repls after x amount of inactivity.
- After finishing the main thread in your program, the code will set itself to being done but if another thread is running, this thread will continue after. However, if the entire Repl gets shut down, then all threads are closed so basically running another thread is a cheap party trick for the UI.
TL;DR: You can’t run the pinger in your Repl, so try running an external pinger. This will work for the very current ecosystem but Replit is migrating to new systems so I can’t say this will work for much longer.
You could consider using the always on powerup. This will cause your Repl to restart once stopped.
Or you could deploy the Repl.