By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

Python is too fast !

P: n/a
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/atlantib...thonutils.html
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <80**************************@posting.google.com >,
Fuzzyman <mi*****@foord.net> wrote:
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).

Jul 18 '05 #2

P: n/a
mi*****@foord.net (Fuzzyman) wrote in message news:<80**************************@posting.google. com>...
[snip..]

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.


I think I was fooled by the fact that adding the print statement
seemed to free up the window. (It was originally only added as a
trace).

What I really wanted to do was to force the window to refresh - a bit
of googling on the subject (and a helpful email from Cameron Laird)
brought me to the Tk update() method which works great.

Unfortunately I can't FTP the code until Monday... but I'm very
pelased with it......

Fuzzy
MANY THANKS
Fuzzyman

http://www.voidspace.org.uk/atlantib...thonutils.html

Jul 18 '05 #3

P: n/a
> 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).


You have two choices as to how to solve this. One is turn your
code into a generator. The gui code then becomes something like:

for word in genanagrams():
<display the anagram>
<possibly call Yield in gui toolkit>

Your other choice is to put your anagram generation into a background
thread, and have it send updates to the main (gui) thread. I have long
since given up on TkInter and use wxPython instead. In wxPython you
can use wx.PostEvent to send updates from worker threads to the
gui thread.

To send information from the main (gui) thread, use a Queue.Queue.
Call put() to add stuff in the main thread, and in the worker threads
call get() to get what they should do. Generally you would use
some sort of message object.

Roger
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.