[Tutor] Thread question
Mike
xchimeras at gmail.com
Wed Oct 17 21:51:04 CEST 2012
Hello,
First, I apologize for not providing a code sample (it's on my work
PC) as I have a general threading logic question. I am using Python
2.6 and the threading module (I can't upgrade to a newer version of
Python).
My program is command line based and is driven by the user making a
selection from the menu. Basically option 1 perform a HTTP GET request
to xyz.com/?get=test. The user supply's a list of target domains and
the query (?get=test) is static. The list of targets can be in the
thousands, so I thought threads with queues would be the best route.
When my program starts I start 50 worker threads and 50 display
threads. The worker threads wait for data in the input queue and
handle the request. If a error is hit the data is logged in the
errors queue. This works great if the user selects option 1, but I am
running into problems when a user selects multiple options. Say a
user selection 1 then option (2) with the targets being the same, but
the query string is now ?get=check. The problem I am facing is when
the threads run with option 1 and hit the initialization they are set
to ?get=test i.e. self.param=param. The param is passed in to the init
of the thread class. When I initialize the class from option 1 I pass
in the param ?get=test and when I initialize the class with option 2 I
pass in the param ?get=check. The default initialization is
self.param="". Depending on which option they select first the thread
will be one of the following: blank, or one of the two options. I
don't know how to update the thread variable when it's running i.e.def
run(self). I realize this sounds all confusing, but I am basically
wondering how one would update a thread variable when it is running?
Also, is it best to spawn threads each time the user make a selection
or once when the program starts?
I appreciate any feedback.
Thank you,
Mike.
More information about the Tutor
mailing list