On Wed, Sep 15, 2021 at 7:43 AM Cameron Simpson <[email protected]> wrote: > > On 14Sep2021 21:43, M.-A. Lemburg <[email protected]> wrote: > >- The context manager is not thread safe. There's no thread safe model > > for the current work dir. OTOH, scripts usually don't use threads, > > so not a big deal. > > This is the source of my concerns. Though of course it applies to any > process global state. It would need this stated up front in big letters > (as of course does chdir itself). My real concern is that this can leak > into other functions whose use then makes whatever uses them to become > inherently and unrepairably not thread safe. > > I know I'm atypical, but I have quite a lot of multithreaded stuff, > including command line code. So while it'd be ok to avoid this context > manager for my own code, I fear library modules, either stdlib or pypi, > quietly using this in their code, making them unuseable in the general > case. Unrepairably unuseable, for the user.
Library code shouldn't be changing the working directory, context manager or not. That belongs to the application. > I think what would be more useful is a context manager which worked on a > threading.local which pushed/popped a reference directory path, and had > an open() method which used that (and friends for other pathname based > functions). Hmm. If it's going to push/pop directories, it should probably work with file descriptors rather than path names, and effectively turn all open calls into openat calls. I'm currently not sure what the best way to do that in Python is. ChrisA _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/VKJDWN6J7NP4GHBBARF44XWTWWD3UCJ4/ Code of Conduct: http://python.org/psf/codeofconduct/
