Wikipedia describes [ Comet] as, "a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.". In other words, Comet is that asynchronous Javascript mojo you need to build really fancy AJAX applications. The following code demonstrates how to write a Comet application using CherryPy and jQuery. It is a web interface into the console ping command. The ping command was chosen for this example because it will run indefinitely if given no arguments. Executing never-ending commands is usually a big no-no when it comes to web application programming but with CherryPy we can handle this quite easily: {{{ #!python #!/usr/bin/env python # -*- coding: utf-8 -*- import os, signal from subprocess import Popen, PIPE # string.Template requires Python 2.4+ from string import Template import cherrypy __author__ = 'Dan McDougall ' # Thanks to joshthecoder for the pid-in-session bit # Trying to cut down on long lines... jquery_url = '' jquery_ui_url = '' jquery_ui_css_url = \ '' class Comet(object): """An example of using CherryPy for Comet-style asynchronous communication""" @cherrypy.expose def index(self): """Return a basic HTML page with a ping form, a kill form, and an iframe""" # Note: Dollar signs in string.Template are escaped by using two ($$) html = """\

CherryPy Comet Example