pnlbwh / dMRIharmonization

Multi-site dMRI harmonization
Other
46 stars 14 forks source link

Use mkstemp to generate a named temporary file #63

Open tashrifbillah opened 4 years ago

tashrifbillah commented 4 years ago

Hi @fedemoro,

To eliminate permission issue regarding writing to /tmp/ directory you were facing because of this line:

# copy provided config file to temporary directory
configFile= f'/tmp/harm_config_{getpid()}.ini'
with open(configFile,'w') as f:
    f.write('[DEFAULT]\n')
    f.write(f'N_shm = {self.N_shm}\n')
    f.write(f'N_proc = {self.N_proc}\n')
    f.write(f'N_zero = {self.N_zero}\n')
    ...
    ...

I would like to devise a solution for you that should also contribute to the impeccability of our software.

Can you try the following on ipython and let me know what you get:

from tempfile import mkstemp
f, name= mkstemp()
print(f, name)
fedemoro commented 4 years ago

Can you try the following on ipython and let me know what you get:

from tempfile import mkstemp
f, name= mkstemp()
print(f, name)

44 /var/tmp/pbs.1337292.pbs/tmpsunczqkv

fedemoro commented 4 years ago

Your previously mentioned solution of changing tmp folder works just fine

cd dMRIharmonization/lib Then, check the occurrences of /tmp/: grep /tmp py sed -i "s+/tmp/+/new_folder/+g" py

tashrifbillah commented 4 years ago

44 /var/tmp/pbs.1337292.pbs/tmpsunczqkv

I didn't know you can have write access to /var/tmp. Good!

Your previously mentioned solution of changing tmp folder works just fine

I provided you a way around, but not the most desired one. Let's say you want to git pull after you affect those changes. Then, you would have to discard the changes one by one until you can pull recent changes of our software. On the other hand, if I write to the system default directory other than /tmp/, then you won't have to affect those changes in first place. So, to make it more manageable and standard, I shall write to system default temp directory.

Please watch for updates. Thanks!

tashrifbillah commented 4 years ago

Hint: Replace configFile= f'/tmp/harm_config_{getpid()}.ini' with follows:

from tempfile import gettempdir
configFile= pjoin(gettempdir(), harm_config_{getpid()}.ini')