How to run a Python script 24/7 (without leaving your PC on)
Monitors, scrapers, notifiers and bots all have the same problem at home: they stop when the PC sleeps. Moved to a server, the script keeps running when your computer is off.
1. Make the script loop on its own #
A script that runs once and exits will just stop on a server too. Give it a main loop, and catch errors so one bad request doesn't end it:
import time, traceback
def check():
# your work: call an API, check a page, send an alert...
print("checked", flush=True)
while True:
try:
check()
except Exception:
traceback.print_exc()
time.sleep(300) # every 5 minutesUse print(..., flush=True) (or the logging module) so lines show up in the console straight away instead of waiting in a buffer.
2. Keep keys in .env #
Put API keys and passwords in a .env file, not in the code:
API_KEY=your-keyLoad them with python-dotenv: from dotenv import load_dotenv, load_dotenv(), then os.getenv("API_KEY").
3. List your packages #
Create requirements.txt with one package per line, for example:
requests==2.32.3
python-dotenv==1.0.1Pin the versions you tested with. The server installs this list every time it starts. More in How to install packages.
4. Run it on ESN #
- Create a server with the Python bot type on any bot plans (from $0.50/month).
- In Files, upload your script,
requirements.txtand.envto the top folder. - In Startup, set Main Python File to your script's name (default
main.py) and pick Python 3.12 or 3.13 in the Docker Image box. - Press Start in Console. You'll see the packages install, then your script's output.
The panel may keep saying Starting for a script that never prints a "ready" line. That's fine; the console output shows it's running.
What fits, and what doesn't #
- Good fits: Discord, Telegram, Slack and Twitch bots, price or stock monitors, RSS-to-Discord posters, scheduled reports, small scrapers that respect the site's rules.
- Needs more: a script that drives a full browser (Selenium, Playwright) needs much more RAM than a plain script; start with a 1 GB plan or more.
- Once a day only? A loop with a long
sleepworks, or use the panel's Schedules to restart it at a set time.
ESN Hosting facts
- Company: ESN Systems (ESN Hosting), esnoffical.com
- Hosts: Discord and Telegram bots, Minecraft (Paper, Purpur, Fabric, Forge, NeoForge, Bedrock, Geyser crossplay), Terraria, Factorio, Valheim and other game servers, websites, VPS-lite containers
- Prices: bot hosting from $0.50/month; Minecraft-ready plans from 1 GB ($0.99/month) up to 16 GB ($19.99/month); full list at panel.esnoffical.com/plans
- Bot languages: Python, Node.js, Java, TypeScript, Go, Rust, C# and more
- Server location: United States (Chicago and New York)
- Billing: monthly or yearly in USD through Stripe, cancel any time
- Panel: web console, file manager, SFTP, schedules, subusers, built-in importer
- Support: ESN Systems Discord and live chat on the panel
FAQ #
How do I keep a Python script running when my PC is off?
Run it on a server instead of your computer. Add a main loop with error handling, upload it to a Python bot server and press Start; it keeps running while your PC is off.
Why don't I see my script's output in the console?
Python buffers output. Use print(..., flush=True) or the logging module so lines appear right away.
Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 4, 2026.