[Tutor] tuples and mysqldb tables (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Sep 19 20:06:24 CEST 2005

[Again forwarding to tutor.  Ed, please keep tutor at python.org in CC;
otherwise, your questions might lose themselves in my mailbox.  I don't
want to be a bottleneck in your learning.]

---------- Forwarded message ----------
Date: Mon, 19 Sep 2005 00:06:13 -0400
From: Ed Hotchkiss <edhotchkiss at gmail.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] tuples and mysqldb tables

Thanks for the debugging help :P - I've edited the error handling line, and
defined the port_counter above, but I am still not getting any output. I
have inserted print "scanned: ",port_counter,"\n"
into the thread, so that should at least print to screen each time the
thread is ran, regardless of the port being open or closed. Any ideas why
the thread itself though is not working?
A cleaner view of the code is here:
 Thanks again for the error handling help!

 On 9/18/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> > def run(self):
> > try:
> > ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > ss.connect((ip, port_counter))
> > print "%s | %d OPEN" % (ip, port_counter)
> > ss.close()
> > except: pass
> ^^^^
> Hi Ed,
> Yikes. Don't do that. *grin*
> By "that", I mean setting the exception handler here to do nothing.
> Exception handling shouldn't abused to silence errors like that, at least,
> not wholesale like that. At the very least, while we're debugging this,
> import the 'traceback' module and at least give a heads up, like this:
> except:
> traceback.print_exc()
> Once this is in place, expect to see errors. I know what you meant to do:
> you wanted to ignore network errors, so try to make the exception handler
> a little more specific in the exceptions it's trying to silence.
> The problem here is that the handler has been inadvertantely silencing a
> legitimate NameError. From casual inspection, it's not clear what
> 'port_counter' is. I suspect you want to add that as part of the thread's
> state, in which case consider adding it within your thread's __init__
> method.
> > def scan(ip, begin, end):
> > for port_counter in range(begin, end):
> > while threading < MAX_THREADS:
> > scanThread().start()
> > # end function -------------------
> Ok, I definitely suspect port_counter now as the culprit here. Make sure
> you create each thread with port_counter as a part of each thread's state.
> [Aside: are you trying to a port scanner in the style that Jacob Matthews
> wrote about here?
> http://www.kuro5hin.org/story/2004/3/17/93442/8657
> Just curious.]
> Good luck to you!

edward hotchkiss

More information about the Tutor mailing list