Python is too fast !

Fuzzyman michael at foord.net
Sat Feb 21 03:39:12 EST 2004


I've written an anagram finder that uses recursion and a large
wordlist to find anagrams of input words you give it (e.g. 'michael
food' = 'cool firm head') ;-)

http://www.voidspace.org.uk/atlantibots/nanagram.html

It has a nice Tkinter front end and works very well, *except* if you
give it a long input it takes a long time to process (as might be
expected) - ten minutes or more sometimes before it returns with the
answers.

I've done a CGI version which returns the answers *whilst* it is
finding them ( http://www.voidspace.xennos.com/cgi-bin/Nanagram-CGI.py
) - which is a much slower method, but less boring to watch.

So I've coded an option - which opens a temporary window with a
Tkinter text widget in a frame and outputs the answers to the window
as it finds them. The trouble is that the recursion is very processor
intensive and it 'freezes' the window and it doesn't update. (I'm
running on an AMD XP1700 with Win XP).

*If* I run this from IDLE and put a print statement into the loop as
well as output to the text widget, then the print statement seems to
free up the widget and it works as it should. I suspect that the print
statement is making system calls which free up the system long enough
to update the screen. When I run it without a console - the benefit is
lost and it freezes again. However I've tried adding a sleep statement
( 0.001, 0.01 and even 0.1 of a second) and this has no effect (other
than slowing down the loop without unfreezing the window).

I'm looking for another suggestion to 'waste time' - preferably in a
'non-processor-intensive' way, that returns control to the sytem for
an instant ? (also preferably cross platform).

If you have a suggestion it would be helpful if you could e-mail it to
me at fuzzyman AT atlantibots DOT org DOT uk as well as post it here -
because I only have intermittent access to the net.


MANY THANKS


Fuzzyman

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list