-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-m cProfile -o f.pstats with a script that does chdir() writes to the changed directory and not .
#84672
Comments
just spent quite a bit of time debugging this, here's a minimal example: # 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: $ 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 |
I think it is worth to fix and it should be not difficult to fix. Either make the output file name absolute before executing the script, or open the output file before executing the script (what is easier). Unless I miss something. |
@serhiy: this was pretty straightfowrard to fix as you suspected -- would you be able to review it? |
I am not sure what is better: to fix it at high level, in main() for cProfile and cProfile, or at low level, in methods runctx() and run() of profile._Utils. |
Maybe both, to keep them decoupled and be sure of correct behavior in all cases? |
Many thanks for the report and the PR, Anthony! Serhiy, do you think it is worth also calling abspath in the profile._Utils as you mentioned, for cases where those may be called directly? |
--outfile
when the program being profiled changes the working directory #19910Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: