basic thread, big problem (logic? - probably)

F

francisl

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
not responding.

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
def start_thread2(servername):
keyinfo = getregkey.getregkey(servername,"Software\Microsoft\DataAccess")
mdac_info.append([servername, keyinfo.GetKey("FullInstallVer")])
keyinfo.CloseKey
# 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"]:
try:
for i in range(thread_info["num_left"]): # how many thread are available to launch
thread.start_new(start_thread2, (serverlist[serverlistlen-1],))
serverlist.remove(serverlist[serverlistlen-1])
serverlistlen = serverlistlen - 1 # remove one possible thread
thread_info["num_left"] = thread_info["num_left"] - 1
except:
pass # if only one server left, but two threads are availlable, it will raise an exception.
else:
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.

Thank you


Francis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top