4

On all the machines on my cluster, my home directory is mounted from the NFS server as /home/drive1/username. On the NFS server, the folder /home/drive1/username is a symbolic link to /drive1/username.

Running:

$ python -c "import os; os.chdir('/home/drive1/username'); print(os.getcwd())"

on any machine other than the NFS server prints:

/home/drive1/username

but on the NFS server, the same command prints:

/drive1/username

Is there any way to prevent Python os.chdir from walking the symbolic link? This makes it difficult to specify the correct path when submit jobs from the NFS server to the worker nodes.


Edit:

Note that

cd /home/drive1/username
pwd

works as expected on all machines.

ostrokach
  • 17,993
  • 11
  • 78
  • 90
  • How is it meant to end up in the right directory if it doesn't follow the symbolic link? Does calling `os.getcwd()` in the script not bypass issue of it being a different location? – Simon Fraser Jul 26 '17 at 20:36
  • 1
    I just want it to work like `cd` and `pwd` in bash. – ostrokach Jul 26 '17 at 20:37
  • 2
    Seems https://stackoverflow.com/a/1545838/3527520 is the answer – Simon Fraser Jul 26 '17 at 20:40
  • This doesn't prevent you from having the same scripts running on both servers, only the scripts must not call `os.getcwd()`, but perhaps `my_own_getcwd()`. – Gribouillis Jul 26 '17 at 20:48
  • 1
    I edited the post. The usecase is submitting jobs from the NFS server to worker nodes using a job scheduler such as Sun Grid Engine. I want to specify the full path to a script, but it's hard to do that from within Python. – ostrokach Jul 26 '17 at 20:52

0 Answers0