I use Google App Engine as backend for an iOS application. I have a separate module that polls the Task Queue, looking for push notifications queued for sending. The module starts a background thread on /_ah/start and runs as long as the module is running.
The backend has dynamic availability, so when there are no requests for a while it will go idle. When there are no instances running, there is no need for the polling either. After I added the module, the billing charges has increased a lot because of instance hours usage. I'm still developing the app and the backend, so the backend is idle most of the time. I thought I could at least manually shut down the module and only turn it on when I need it for testing. But the module restarts by itself immediately after I shut it down...
How can I implement a good "cooperation" between the default module and the polling module, so that if there are no instances running on the default module, the polling module will automatically shut down?