jupyterlab-slurm
jupyterlab-slurm copied to clipboard
Patch to use Python's tempfile library instead of 'temporary_file.temporary'
Under certain circumstances using the hardcoded path temporary_file.temporary
can be problematic. For instance, if the starting directory for a Jupyter notebook instance is not writable by the user that started the notebook, trying to submit a fully typed out batch script will fail silently. There also may be contention issues in multi-user environments (i.e., a JupyterHub deployment) where multiple users start out in the same directory, since multiple users may try to write to the same temporary file at the same time.
This patch tries to mitigate these issues by using Python's built-in tempfile
library to systematically create tempfiles that are exclusively/uniquely allocated to individual users in a location that is known to be writable. Since tempfile.mkstemp()
returns an absolute path in /tmp
(or the equivalent), there is no potential for an end-user to accidentally try to write to an unwritable directory.
This seems like a reasonable fix, and also addresses a race condition for multiple job submissions.
The one other addition I would suggest is that we may want these files sitting in the users home directory rather than /tmp. We could make that configurable.