[New-bugs-announce] [issue40492] -m cProfile -o f.pstats with a script that does chdir() writes to the changed directory and not `.`

Anthony Sottile report at bugs.python.org
Sun May 3 23:36:27 EDT 2020


New submission from Anthony Sottile <asottile at umich.edu>:

just spent quite a bit of time debugging this, here's a minimal example:

```bash
# rm -rf a (if you want to reset)
cd /tmp
mkdir -p a/b
echo 'import os; os.chdir("..")' > a/b/c.py
cd a/b
python3 -m cProfile -o log.pstats c.py
ls -al
ls -al ..
```

example output:

```console
$ cd /tmp
$ mkdir -p a/b
$ echo 'import os; os.chdir("..")' > a/b/c.py
$ cd a/b
$ python3 -m cProfile -o log.pstats c.py
$ ls -al
total 12
drwxr-xr-x 2 asottile asottile 4096 May  3 20:35 .
drwxr-xr-x 3 asottile asottile 4096 May  3 20:35 ..
-rw-r--r-- 1 asottile asottile   26 May  3 20:35 c.py
$ ls -al ..
total 16
drwxr-xr-x  3 asottile asottile 4096 May  3 20:35 .
drwxrwxrwt 28 root     root     4096 May  3 20:35 ..
drwxr-xr-x  2 asottile asottile 4096 May  3 20:35 b
-rw-r--r--  1 asottile asottile  395 May  3 20:35 log.pstats
```

happy to work on a patch if this seems like a good idea to fix

----------
components: Library (Lib)
messages: 368008
nosy: Anthony Sottile
priority: normal
severity: normal
status: open
title: -m cProfile -o f.pstats with a script that does chdir() writes to the changed directory and not `.`
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40492>
_______________________________________


More information about the New-bugs-announce mailing list