threads/sockets quick question.

Piet van Oostrum piet at cs.uu.nl
Mon Sep 19 05:02:26 EDT 2005


>>>>> Bryan Olson <fakeaddress at nowhere.org> (BO) wrote:

>BO> ed wrote:
>>> this script should create individual threads to scan a range of IP
>>> addresses, but it doesnt, it simple ... does nothing. it doesnt hang
>>> over anything, the thread is not being executed, any ideas anyone?

>BO> It's because of the bugs. Nothing happens because

>BO>      threading < MAX_THREADS

>BO> is always false. You are comparing a module to an int. Next,
>BO> you never create any instances of scanThread. Next the local
>BO> variables of scan() are not visible in scanThread.run().

And even if they were (for example if port_counter is made global), you
can't rely on it having the intended value in scanThread.run. You should
pass the port_number as a parameter to the thread.

And if the test for the number of threads was done properly, it would
swallow up all available threads for one port_number, rather than starting
one thread per port_number. And it doesn't handle the case when the threads
are exhausted: it should wait until a thread becomes available before
continuing. 
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list