web status display for long running program
Michele Simionato
michele.simionato at gmail.com
Fri Feb 25 06:34:47 EST 2005
This is fun, so I will give my solution too (of course,
the effort here is to give the shortest solution, not the
more robust solution ;).
This is the server program, which just counts forever:
from threading import Thread
from CGIHTTPServer import test
import os
class Counter(Thread):
def run(self):
n = 0
self.loop = True
while self.loop:
n += 1
os.environ["COUNTER"] = str(n)
def stop(self):
self.loop = False
if __name__ == "__main__":
counter = Counter()
counter.start()
try:
test()
finally: # for instance, if CTRL-C is called
counter.stop()
And this is the CGI viewer:
#!/usr/bin/python
import os
print "Content-type: text/plain\n"
print "Counter: %s" % os.environ["COUNTER"]
Pretty bare-bone ;)
Michele Simionato
More information about the Python-list
mailing list