Not sure about this, as this can run into problems with future code that also tries to manipulate the working directory. It'll also have problems if your chdirs are unrolled out of order, though I can see stackframe-based assumptions being made about generator timing.

I suppose I'm never happy about global state manipulation like this. I can see this being kept for reasons of simplicity, but I think it would be better to run a thread or subprocess in the correct directory instead, noting the potential performance pitfalls outlined in http://stackoverflow.com/questions/2629680/deciding-between-subprocess-multiprocessing-and-thread-in-python.