I think there is some lock problem.
Let me show the code first
from time import sleep
_hostname = None
_username = None
_password = None
_ldapDataFile = None
if _hostname is None or _username is None or _password is None or _ldapDataFile
sys.stderr.write("Please first set the credentials properly.\n")
_ldapPreCommand = 'ldapsearch -LLL -z 0 "(Sn='
_ldapPostCommand = '*)" -h ' + _hostname + ' -x -D "' + _username + '" -b
Cn=users,DC=hq,DC=domain,DC=com' + " -w " + _password
NumberOfThreads = 5
#char = 's'
#ldapCommand = _ldapPreCommand + char + _ldapPostCommand
#x = os.system(ldapCommand)
#if x == 1024:
# print "I'm in the exception"
['dn:', 'cn:', 'sn:', 'l:', 'st:', 'title:', 'description:', 'postalCode:', 'telephoneNumber:', 'facsimileTelephoneNumber:',
'givenName:', 'mail:', 'homePhone:', 'mobile:', 'pager:']
writeFile = open(_ldapDataFile, 'w')
sys.stderr.write("Couldn't open file %s to write.\n" % (writeFile) )
#print "Writing data to %s\n" % (temp_file_name)
(temp_file_fd, temp_file_name) = tempfile.mkstemp()
os.environ['__kabc_ldap'] = temp_file_name
sleep(5) #Let's not thrash the exchange server ;-)
ldapCommand = _ldapPreCommand + char + _ldapPostCommand
if os.system(ldapCommand + "> $__kabc_ldap") != 0:
sys.stderr.write("Couldn't execute the command %s\n" %
#temp_file_name = "/tmp/tmpnhYrps"
readFile = open(temp_file_name, 'r')
sys.stderr.write("Couldn't open file %s to read.\n" % (readFile) )
for record in readFile.readlines():
if record.startswith(' '): # Remove the junk
record = string.rstrip(record, "\n")
for attrib in ldap_attributes:
if ldap_attributes == attrib: #This attribute is
common/mandatory in all records, so we can rely on it
def run(request, response, func=RecordFetcher):
item = request.get()
if item is None:
(char, subChar) = item
# Start from here
requestQueue = Queue.Queue()
responseQueue = Queue.Queue()
FileLock = threading.Lock()
thread_pool = [
for i in range(NumberOfThreads)
for t in thread_pool: t.start()
for char in string.lowercase:
# I know this is ugly. Too many cycles
# But ldapsearch or exchange is restricting, the query max result limit is
for subChar in string.lowercase:
requestQueue.put( (char, subChar) )
for t in thread_pool: requestQueue.put(None)
for t in thread_pool: t.join()
Now as per the above code, "aa" is the first string which will be executed in
Thread-1. In my query to the ldap server, I am getting a record which matches
the "aa" string. I've verified it by putting a breakpoint and checking the
The problem is that when I run the program manually, I don't get the data from
the first thread i.e. of the string "aa".
I'm not sure if there's something wrong in the code mentioned above or is it
really a lock problem.
Can somebody please help about where I'm doing any mistake ?
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."
"Stealing logic from one person is plagiarism, stealing from many is research."
"The great are those who achieve the impossible, the petty are those who
cannot - rrs"