473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Python is too fast !

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
3 1428
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
83
by: Licheng Fang | last post by:
Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include <iostream> #include <string> #include <vector> #include <set> #include...
0
by: eGenix Team: M.-A. Lemburg | last post by:
________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.1.1 for Python 2.6 Open Source Python extensions providing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.