[Tutor] Help debuging a small program

Martin Walsh mwalsh at groktech.org
Tue Feb 22 20:11:43 CET 2005

Mark Kels wrote:

>On Mon, 21 Feb 2005 13:21:35 -0500, Kent Johnson <kent37 at tds.net> wrote:
>>How far does it get? How do you know?
>>I would put some debug print statements in. Also you should call sk.close() in the else clause of
>>scan(). Finally, I don't think you will see any output in the result window until get_info()
>>returns; you have to give some time to mainloop() for it to be able to trigger the updates.
>I don't understand how to prevent the program from crashing right now...
>I'll deal with other bugs when I'll finish this one :)
>So, why does the program crashes and how can I prevent it ??
>Thanks !!
Hi Mark,

I believe Kent has given you the solution, it's perhaps just not what 
you expected it to be. Adding debug print statements might have helped 
you to see. To demonstrate further try scanning only 1 or 2 ports.

When your app appears to be frozen or crashing, I suspect it is happily 
scanning away. Looks like you have an overly ambitious while loop in the 
scan function, which isn't giving the Tk Text widget (result_t?) time to 

Someone more experienced that I will certainly have a better way, but 
you might try adding root.update() at the end (but inside) the while 
loop to force an update.

# + ---The Scan---
def scan(host,start_port,end_port):
    sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    while start_port<=end_port:
            result_t.insert(END,"Port",start_port,"is CLOSED on",host,"\n")
            result_t.insert(END,"Port",start_port,"is OPENED on",host,"\n")
        root.update() #<<-- add this

and have a look here 

 >>> import Tkinter
 >>> help(Tkinter.Tk)
Help on class Tk in module Tkinter:
 |  update(self)
 |      Enter event loop until all pending events have been processed by 
 |  update_idletasks(self)
 |      Enter event loop until all idle callbacks have been called. This
 |      will update the display of windows but not process events caused by
 |      the user.

More information about the Tutor mailing list