web status display for long running program
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The type and amount of status information doesn't fit nicely into a --verbose or logger -- either too little or too much information at different points. I think an optional web page would be convenient interface. The Python program would listen on some port, and if queried (by me browsing to localhost:12345 for example) would return a pretty status display. Hitting reload would update the status etc. My problem is that I'm not sure how to do this: - I don't want to embed a full web server into the application or require any special PC setup. - I think I know how to listen on a socket, but not sure how to send stuff to to a web browser -- just start with ? Or like a CGI script with the header stuff like text/html? (I don't care if I have to write the HTML by hand or can use a toolkit -- not important). - Do I need a separate thread to listen and send the HTML? The application is currently single threaded. I'm confortable with threads, but would prefer to avoid them if possible. Or is there a better/different way of doing this? Any general advice or pointers to some code that already does this would be very much appreciated. Python 2.3, under both Linux & Windows if that makes a difference. Thanks, Brian. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for way to include many times some .py code from anotherpython code
> > Am I so deperately fighting the language? No-one here on the list needs to > set hundreds > variables at once somewhere in their code? I still don't get why: > I once (and only once) needed hundreds of variables in a program. It was to simplify creation of unit tests, not for production use. The variable names and data (representing a graph with named nodes) was stored in a text file, I read that file and used setattr() to create each variable. This was in a module that did nothing else, and was imported by unit test code that benefited from the names when setting up easily readable test cases. Background if you're new to Python: importing a module *executes* it; for most modules the only important stuff executing is the class and def statements. However, you can execute more stuff when (rarely) necessary -- reading a file in my case. This is very different than, say, C or C++, which has separate include and execute steps. In general, you want to either use the built-in lists and dicts, or create classes/objects to represent hundreds of things. Brian. -- http://mail.python.org/mailman/listinfo/python-list
empty lists vs empty generators
I'm using using generators and iterators more and more intead of passing lists around, and prefer them. However, I'm not clear on the best way to detect an empty generator (one that will return no items) when some sort of special case handling is required. Typical code for handling an empty list: if somelist: for x in somelist: something(x) else: empty_list_special_case But this doesn't work with iterators -- a generator is "true" regardless of whether its going to return any items. (I understand why). The closest equivalent I know of is: n = 0 for n, x in enumerate(somegenerator()): something(x) if n == 0: empty_list_special_case Which seems rather awkward -- doesn't read as easily for me, and introduces another variable. Q1: Is there a better or alternate way to handle this? Q2: Is there a way that handles both lists and generators, so I don't have to worry about which one I've got? Thanks, Brian. -- http://mail.python.org/mailman/listinfo/python-list
