Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   basic thread, big problem (logic? - probably) (http://www.velocityreviews.com/forums/t340546-basic-thread-big-problem-logic-probably.html)

francisl 01-21-2005 03:38 AM

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
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




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.