[issue42796] tempfile doesn't seem to play nicely with os.chdir on Windows

2021-01-01 Thread Eryk Sun
Eryk Sun added the comment: > def test_chdir(): > with tempfile.TemporaryDirectory() as tempdir: > old = os.getcwd() > os.chdir(tempdir) > with open(os.path.join(tempdir, "delme")) as fout: > fout.write("Hello") > os.chdir(old) The open() call in

[issue42796] tempfile doesn't seem to play nicely with os.chdir on Windows

2021-01-01 Thread Eryk Sun
Eryk Sun added the comment: > Windows doesn't let you remove files and directories that are used > by a process. Windows does allow deleting open files/directories, but read/execute, write/append, and delete/rename access have to be explicitly shared when opening a file or directory. WinAP

[issue42796] tempfile doesn't seem to play nicely with os.chdir on Windows

2021-01-01 Thread Gabriele Tornetta
Gabriele Tornetta added the comment: That makes sense, but I wonder what the "right" behaviour should be in this case. Surely the infinite recursion should be fixed at the very minimum. Perhaps the code on Windows could be enhanced to catch the case whereby one is trying to delete the cwd an

[issue42796] tempfile doesn't seem to play nicely with os.chdir on Windows

2021-01-01 Thread Christian Heimes
Christian Heimes added the comment: The code fails because TemporaryDirectory.__exit__() is unable to remove the directory. Windows doesn't let you remove files and directories that are used by a process. On POSIX-like operating systems like Linux support removing of opened files. For exampl

[issue42796] tempfile doesn't seem to play nicely with os.chdir on Windows

2020-12-31 Thread Gabriele Tornetta
New submission from Gabriele Tornetta : The following script causes havoc on Windows while it works as expected on Linux ~~~ python import os import tempfile def test_chdir(): with tempfile.TemporaryDirectory() as tempdir: os.chdir(tempdir) ~~~ Running the above on Windows resu