> On Sep 15, 2021, at 4:11 AM, Christian Heimes <christ...@python.org> wrote: > > On 15/09/2021 09.21, Eric V. Smith wrote: >>> On 9/15/2021 3:02 AM, Christian Heimes wrote: >>> On 15/09/2021 01.55, Guido van Rossum wrote: >>>> I know where I'd file a bug. :-) >>>> >>>> "Bug magnet" is an extremely subjective pejorative term. When the >>>> *better* way to do things (os.workdir()) is harder than the *easy* way >>>> to do (os.chdir()), which is the real bug magnet? >>> The "better way" to handle current working directory is to use the >>> modern *at() variants of syscalls, e.g. openat() instead open(). The >>> variants take an additional file descriptor dirfd that is used as the >>> current working directory for the syscall. >> >> While I generally agree, the only times I've written a context manager >> like os.workdir() is when running an executable with subprocess.call(), >> and the executable requires that its current directory be set to some >> specific directory. So while I don't use this functionality very often, >> there are times when nothing else will do. I realize I could handle this >> temporary working directory with yet another executable (including a >> shell), but using a context manager is just easier, and I only use this >> in single-threaded programs. > > You don't have to change the current working directory of your process > in order to run a child process in a different working directory. > subprocess.call() and other functions in the subprocess module accept a > "cwd" argument that lets you run a process with a different working > directory. The "cwd" argument is thread safe.
I learned something today. Thanks! Eric _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MTNIK4Q3AQH5Q7IVA44EFPMJODCUWAIN/ Code of Conduct: http://python.org/psf/codeofconduct/