Speed up with threads
Skip Montanaro
skip at pobox.com
Sun Aug 4 07:27:35 EDT 2002
>> Have a look at the Queue module.
raims> I read both the Queue doc and the Aahz slides but I still have
raims> problems... what goes in the Queue? How to use get() and put(), I
raims> have to scan ports not to share data... I think
Here's how I'd use Queues in this situation. Create a fixed set of threads
(make them daemons) which are going to do nothing more than grab a port to
scan from the queue, do something with the results, then repeat. The main
thread adds port information to the queue. Once all the ports have been fed
to the queue, the main thread waits for the queue to empty. Once it's
empty, it exits. The application as a whole will then exit because the
other threads are daemons.
By having a fixed set of threads to handle the requests you can limit the
number of simultaneous scans running and eliminate the thread creation per
port issue, which is very likely to slow down your application.
--
Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html
More information about the Python-list
mailing list