Hello, I'm running a Python bot using APScher still stops automatically after a few seconds. My logs show:
victor-svg1
FREEOP

8 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.

$10 Bounty

6 Replies

noahd
EMPLOYEE

8 months ago

Is it being run as a background task?


idiegea21
HOBBY

8 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.


sim
FREE

7 months ago

Can you make sure serverless is not enabled? https://docs.railway.com/reference/app-sleeping


sim
FREE

7 months ago

I doubt that is the issue though actually. Can you share your code or the script?


sim
FREE

7 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


jetsetbrand
FREE

7 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.

white_check_mark emoji 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


Loading...