Re: lock problem
On Mar 16, 3:08 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Leo Kislov wrote: > > But you miss the fact that there is only one environment per process. > > Maybe there's a confusion. > The environment variable that I'm setting has noting to do with ldapsearch. I > use the environment variable as a filename to which ldapsearch can redirect > its > output. And that I do is because the output can be huge and useless. > Then I do some pattern matching on that file and filter my data and then > delete > it. > > If you think I still am missing something important, request you to describe > it. Imagine this timeline: os.environ['__kabc_ldap'] = '/tmp/tmp1' os.environ['__kabc_ldap'] = '/tmp/tmp2' launch ldapsearch (output goes to '/tmp/tmp2') launch ldapsearch (output goes to '/tmp/tmp2' over output from ldapsearch launched from thread1) Seems like that's what is happening to your program. -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
En Fri, 16 Mar 2007 19:08:14 -0300, Ritesh Raj Sarraf <[EMAIL PROTECTED]> escribió: >> But you miss the fact that there is only one environment per process. > > Maybe there's a confusion. > The environment variable that I'm setting has noting to do with > ldapsearch. I > use the environment variable as a filename to which ldapsearch can > redirect its > output. And that I do is because the output can be huge and useless. > Then I do some pattern matching on that file and filter my data and then > delete > it. > > If you think I still am missing something important, request you to > describe it. Then, why do you use an environment variable? Just redirect the output to the desired file name (when you are making the command line to be executed by os.system) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
Leo Kislov wrote: > But you miss the fact that there is only one environment per process. Maybe there's a confusion. The environment variable that I'm setting has noting to do with ldapsearch. I use the environment variable as a filename to which ldapsearch can redirect its output. And that I do is because the output can be huge and useless. Then I do some pattern matching on that file and filter my data and then delete it. If you think I still am missing something important, request you to describe it. Thanks, Ritesh -- 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" -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
Leo Kislov wrote: > But you miss the fact that there is only one environment per process. > Oh!! I think I get your point. There'd be only one __kabc_ldap environment variable to which all the threads would be overwriting. Hmmm!! Yes, you're correct. Thanks for pointing it out. Ritesh -- 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" -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
En Fri, 16 Mar 2007 04:40:27 -0300, Ritesh Raj Sarraf <[EMAIL PROTECTED]> escribió: > Leo Kislov wrote: > >> You're changing environmental variable __kabc_ldap that is shared >> between your threads. Environment is not designed for that kind of >> usage, it was designed for settings. Either use an option to set >> output file or just redirect stdout. If the interface of ldapsearch is >> so lame that it requires environmental variable use env to set the >> variable: "env __kabc_ldap=/tmp/wrjhdsf ldapsearch ..." > > The environment variable is set with temp_file_name which gets the name > from > tempfile.mkstemp(), which is run in every thread. So I don't think the > environment variable is going to be the same. But the environment is global for all threads. I don't know how ldapsearch works, but can't you pass it an additional argument, instead of setting an environment variable? From the long commandline you're building, I bet it has a suitable option. Or, instead of os.system, use subprocess.Popen, wich lets you specify the new environment of the child process. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
On Mar 16, 12:40 am, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Leo Kislov wrote: > > You're changing environmental variable __kabc_ldap that is shared > > between your threads. Environment is not designed for that kind of > > usage, it was designed for settings. Either use an option to set > > output file or just redirect stdout. If the interface of ldapsearch is > > so lame that it requires environmental variable use env to set the > > variable: "env __kabc_ldap=/tmp/wrjhdsf ldapsearch ..." > > The environment variable is set with temp_file_name which gets the name from > tempfile.mkstemp(), which is run in every thread. So I don't think the > environment variable is going to be the same. But you miss the fact that there is only one environment per process. -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
Leo Kislov wrote: > You're changing environmental variable __kabc_ldap that is shared > between your threads. Environment is not designed for that kind of > usage, it was designed for settings. Either use an option to set > output file or just redirect stdout. If the interface of ldapsearch is > so lame that it requires environmental variable use env to set the > variable: "env __kabc_ldap=/tmp/wrjhdsf ldapsearch ..." The environment variable is set with temp_file_name which gets the name from tempfile.mkstemp(), which is run in every thread. So I don't think the environment variable is going to be the same. Ritesh -- 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" -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
Gabriel Genellina wrote: > En Thu, 15 Mar 2007 18:31:29 -0300, Ritesh Raj Sarraf <[EMAIL PROTECTED]> > escribió: > >> I'm not sure if there's something wrong in the code mentioned above or >> is it >> really a lock problem. > > Try to break the code into smaller pieces to see what is wrong. It's too > long for somebody to try to understand it. > The only break I can do is to remove threading, and the it works fine. I also noticed that when debugging the threads (when the program stops at a breakpoint in the thread), data is written properly. This is what made me think if this really is a locking problem. Ritesh -- 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" -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
On Mar 15, 2:31 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: [snip] > os.environ['__kabc_ldap'] = temp_file_name [snip] > 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 > value. > > 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 ? You're changing environmental variable __kabc_ldap that is shared between your threads. Environment is not designed for that kind of usage, it was designed for settings. Either use an option to set output file or just redirect stdout. If the interface of ldapsearch is so lame that it requires environmental variable use env to set the variable: "env __kabc_ldap=/tmp/wrjhdsf ldapsearch ..." -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: lock problem
En Thu, 15 Mar 2007 18:31:29 -0300, Ritesh Raj Sarraf <[EMAIL PROTECTED]> escribió: > I'm not sure if there's something wrong in the code mentioned above or > is it > really a lock problem. Try to break the code into smaller pieces to see what is wrong. It's too long for somebody to try to understand it. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list