Depending on what type of backend you are using, "Resident Backends" cannot be disabled from the working environment only through the administrator console or on the command line, while "Dynamic Backends" will be disabled after a few minutes of inactivity.
So, if you use Dynamic Backends, you can simply send a request that says to stop what it is doing and it will be automatically disconnected.
http://code.google.com/intl/iw/appengine/docs/python/config/backends.html#Types_of_Backends
Edit
An example of how this might work:
from google.appengine.ext import webapp from google.appengine.api import memcache from google.appengine.ext.webapp.util import run_wsgi_app import time class ShutdownHandler(webapp.RequestHandler): def get(self): memcache.put('backendShutdown', True, 60) class StartHandler(webapp.RequestHandler): def get(self): lastCheck = time.time() while True: if time.time() - 60 > lastCheck: stopBackend = memcache.get('backendShutdown') if stopBackend: memcache.delete('backendShutdown') break lastCheck = time.time() if __name__ == '__main__': _handlers = [(r'/_ah/start', StartHandler), (r'/backend/worker/shutdown', ShutdownHandler)]
And to stop this, you should use:
from google.appengine.api import backends, urlfetch url = backends.get_url('worker') + '/backend/worker/shutdown' urlfetch.fetch(url)
source share