9 months ago
I’m using `stop_event.wait()` at the end of the script to keep the process alive, but the container still shuts down shortly after booting. The project is set to "Always Running" and no errors appear.
Any idea why this is happening? Is there something I might be missing to keep the service alive?
Thanks in advance.
6 Replies
9 months ago
Hello
stop_event.wait() is not enough, Railway shuts down containers with no network activity.
So i think the approach solution here will be to run a HTTP server( Flask , Django, etc.) that listens on a PORT and bind it to $PORT.
8 months ago
Can you make sure serverless is not enabled? https://docs.railway.com/reference/app-sleeping
8 months ago
I doubt that is the issue though actually. Can you share your code or the script?
8 months ago
Alternatively if this is a scheduled job have you tried using cron in Railway https://docs.railway.com/reference/cron-jobs
Share some of your code and I can help set it up
8 months ago
Your script is not the container’s main process
If you’re running your Python script via something like a CMD that launches a shell script or another process which exits, then the container shuts down even if your script is still running in a subprocess.
Fix: Make sure your Python script is the main process, not a subprocess.
Your Dockerfile should end like this:
CMD ["python", "your_script.py"]
Not this:
CMD ./start.sh # if start.sh launches python in background or non-blocking way