> However, it isn't quite as simple as it seems, as chdir is a
> process-wide attribute, so two threads doing a chdir with a block would
> clash. The interpreter currently gets around this by banning chdirs
> while another chdir block is running.

Could it not just queue the threads?  Note: I don't know much about
threads!

Ie, could the interpreter not do something like keep a queue of threads
that have chdir-ed (or attempted to do so) and process them in that
order?

Or perhaps, protect chdir-ed blocks via a mutex somehow?