basic thread, big problem (logic? - probably)
I'm quite new to code with thread. I found that it is useful for graphical
programming, but now I would like to add this to some of my program.
I tried something but I think I'll have to read a little more on it.
What my program do, is to query a microsoft AD to find all servers in it, then
it query all of those servers for some information on their registry keys. In
fact, everything work well, but the whole process take more than 30 minutes.
Most of the waiting is cause by the "waiting for time out" when server are
So what I try to do, is to start two threads at a time, then if one get
busy, the other one can continue with other query. But my code somehow failed,
it is faster, but one save minute on 30, it clearly demonstrate that my
code is wrong.
here is the section of the my "thread starter" :
# ## this start the request and set value in the array - this is the code to be threaded
keyinfo = getregkey.getregkey(servername,"Software\Microsoft \DataAccess")
# free one thread after completion
thread_info["num_left"] = thread_info["num_left"] + 1
# the "threader"
# serverlist is the actual list of servers that come from the active directory query(LDAP)
# serverlistlen is the __len__() of this list
def start_thread(serverlist, serverlistlen):
while serverlistlen > 0: # while there's server to query
# if there's thread available for processing
if thread_info["num_left"] > 0 and thread_info["num_left"] <= thread_info["max"]:
for i in range(thread_info["num_left"]): # how many thread are available to launch
serverlistlen = serverlistlen - 1 # remove one possible thread
thread_info["num_left"] = thread_info["num_left"] - 1
pass # if only one server left, but two threads are availlable, it will raise an exception.
pass # loop
the probleme is that the loop get stuck often, like the two threads were use and waiting (to many time than possible), but even so it should loop an take the 'else' path, but it does not.
If my logic is totally wrong, I would appreciate to have a word on a good book/tutorial/guide available to code with thread in python.
|All times are GMT. The time now is 04:35 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.