Threads execute in parallel, or at least they alternate back and forth
very quickly. So imagine thread t1 does:
chdir to B
write file C

and thread t2 does
chdir to D
write file E

But in reality the threads are going at the same time so things can
get mixed up like so:

t1 - chdir to B
t2 - chdir to D
t1 - write file C <-- woops. landed in the wrong directory

The easiest solution is to just use full paths and skip the chdir as
Gary pointed out.

Another solution would be to put locks around the mutually exclusive
code, but I wouldn't go that route for something that is so easy to
fix.

To sum up, you only get one current directory per process, not per thread.

HTH,
-Chuck


On 9/14/06, John Dickinson <[EMAIL PROTECTED]> wrote:
> Maybe I'm a little dense here, but I'm not seeing why os.chdir is such a
> bad thing in a threaded environment. I did a little google-ing, but I
> did not find anything the was talking about problems in a threaded
> environment.
>
> I would guess that maybe the issue is that module references could get a
> little wonky if two threads reference the same module and one uses
> os.chdir. Then maybe that thread's module reference is off and it messes
> up any object that may be common to both threads. But that's just a
> guess, and I really don't know a lot about the specifics of imports or
> module references.
>
> Could you explain the issue, please?
>
> --John
>
> Gary Perez wrote:
> >
> >
> > Don't use os.chdir() in a threaded environment.
> >
> > I apologize to everyone if this is common knowledge, but it's news to
> > me. At Chris' suggestion, removing the chdir calls in the two modules
> > fixes the problem, and everything works as expected.
> >
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Webware-discuss mailing list
> Webware-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/webware-discuss
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to