basic thread, big problem (logic? - probably)

Discussion in 'Python' started by francisl, Jan 21, 2005.

  1. francisl

    francisl Guest

    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
    francisl, Jan 21, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shaguf
    Replies:
    0
    Views:
    332
    Shaguf
    Dec 24, 2008
  2. Shaguf
    Replies:
    0
    Views:
    435
    Shaguf
    Dec 26, 2008
  3. Shaguf
    Replies:
    0
    Views:
    222
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    204
    Shaguf
    Dec 24, 2008
  5. Tom Ha
    Replies:
    6
    Views:
    83
    List.rb
    May 7, 2009
Loading...

Share This Page