Forums

using timer

hello all,

I'm very new to python, so please if my question look silly be kind :)
I have a question that I guess is half python coding and half pythonanywhere.

I tried to upload a simple server, that send push notification to my phone every minute (just for testing),
to do so I uses a timer:

  def start_timer(token):
    interval = 60*1

    def timer_tick():
        print('>>>>>>>>>> timer tick')
        msg = 'some message'
        apns.send_push(token, msg)

        timer = threading.Timer(interval, timer_tick)
        timer.start()
        return 1

    return timer_tick()

at first It look like the timer wasn't firing, and I thought it has something to do with the fact that it uses threads, and maybe the pythonanywhere env don't allow that.

but somehow its start working, and now I get push to my phone every minute, the problem is, I don't know how to stop it!
I tried to change the code and reload the server, I even deleted the app, but I still get the push.

so I have 2 questions:
1. first does this code suppose to work? I mean can I use timer in pythonanywhere env?
2. is it possible that using the timer cause it to run on a separate process that I can't stop?

Hi there,

We don't support threading in web apps, so it's not surprising that you're seeing weird results.

At the moment, PythonAnywhere isn't a great platform for an app that requires push notifications. You could conceivably use our scheduled task system to run a task every hour (or even several tasks that ran every hour), and sent out notifications, but that would still be quite asynchronous...

hi harry, can you please answer my second question, is it possible that timer keep firing in a separate process? and if so how can I kill it?

Sorry eyal, yes it's possible it got disconnected. I'll go and see if I can find it and kill it for you...