Forums

web2py - consoles are dead after a while

I'm trying to have a background task for handling emails, as suggested by the web2py Doc

Specifically, I have a python script named mail.py that goes like this:

import time
from gluon.tools import Mail
mail = Mail()
mail.settings = ....
while True:
    .....
    SEND EMAILS
    ....
    time.sleep(3600)

And I run it, as suggested by the docs, from the console as

python web2py.py -S APPLICATION_NAME -M -R applications/.../private/mail.py

The problem is that the console seems to die after a while. When I come back to the dashboard after a day or too, the console is empty. Is this a problem with pythonAnywhere or web2py?

Hi yohai,

Consoles do sometimes get reset as we replace old servers or do maintenance reboots.

The best solution for this would probably to use a scheduled task (see the Schedule tab). You can re-write the above script without the while True and time.sleep, and set it to run once a day, or once an hour...