Skip to content
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

Use mkstemp to generate a named temporary file #63

Open
tashrifbillah opened this issue Apr 15, 2020 · 4 comments
Open

Use mkstemp to generate a named temporary file #63

tashrifbillah opened this issue Apr 15, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@tashrifbillah
Copy link
Collaborator

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)
@tashrifbillah tashrifbillah added the enhancement New feature or request label Apr 15, 2020
@tashrifbillah tashrifbillah self-assigned this Apr 15, 2020
@fedemoro
Copy link

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
Copy link

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

tashrifbillah commented Apr 17, 2020

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants