Skip to content

Commit e029ad2

Browse files
committed
don't modify the umask so much with the job.sh file
1 parent a84b489 commit e029ad2

File tree

8 files changed

+25
-9
lines changed

8 files changed

+25
-9
lines changed

jobqueues/celeryfiles/tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _createJobScript(
8181
fname, workdir, runsh, deviceid, sentinel, datadir, copyextensions
8282
):
8383
import os
84+
from jobqueues.util import _makeExecutable
8485

8586
with open(fname, "w") as f:
8687
f.write("#!/bin/bash\n\n")
@@ -105,4 +106,4 @@ def _createJobScript(
105106
if os.path.abspath(odir) != os.path.abspath(workdir):
106107
f.write("\nmv {} {}".format(" ".join(copyextensions), odir))
107108

108-
os.chmod(fname, 0o700)
109+
_makeExecutable(fname)

jobqueues/localqueue.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def run_job(self, deviceid):
112112
logger.info("Shutting down worker thread")
113113

114114
def _createJobScript(self, fname, workdir, runsh, gpudevice=None):
115+
from jobqueues.util import _makeExecutable
116+
115117
with open(fname, "w") as f:
116118
f.write("#!/bin/bash\n\n")
117119
# Trap kill signals to create sentinel file
@@ -137,7 +139,7 @@ def _createJobScript(self, fname, workdir, runsh, gpudevice=None):
137139
if os.path.abspath(odir) != os.path.abspath(workdir):
138140
f.write("\nmv {} {}".format(" ".join(self.copy), odir))
139141

140-
os.chmod(fname, 0o700)
142+
_makeExecutable(fname)
141143

142144
def _setRunning(self, path):
143145
self._states[path] = "R"
@@ -433,7 +435,7 @@ def _getmemory(self):
433435
from math import floor
434436
import psutil
435437

436-
memory = psutil.virtual_memory().total / 1024 ** 2
438+
memory = psutil.virtual_memory().total / 1024**2
437439
memory *= max(0, min(1, self.ncpu / psutil.cpu_count())) # Clamp to [0, 1]
438440
memory = int(floor(memory))
439441

jobqueues/lsfqueue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def _find_binary(binary):
215215
return ret
216216

217217
def _createJobScript(self, fname, workdir, runsh):
218-
from jobqueues.util import ensurelist
218+
from jobqueues.util import ensurelist, _makeExecutable
219219

220220
workdir = os.path.abspath(workdir)
221221
with open(fname, "w") as f:
@@ -279,7 +279,7 @@ def _createJobScript(self, fname, workdir, runsh):
279279
os.makedirs(datadir, exist_ok=True)
280280
f.write(f"\nmv *.{self.trajext} {datadir}")
281281

282-
os.chmod(fname, 0o700)
282+
_makeExecutable(fname)
283283

284284
def retrieve(self):
285285
# Nothing to do

jobqueues/pbsqueue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def _find_binary(binary):
142142
return ret
143143

144144
def _createJobScript(self, fname, workdir, runsh):
145+
from jobqueues.util import _makeExecutable
146+
145147
workdir = os.path.abspath(workdir)
146148
if not self.queue and self.ngpu > 0:
147149
self.queue = "gpgpu"
@@ -186,7 +188,7 @@ def _createJobScript(self, fname, workdir, runsh):
186188
os.makedirs(datadir, exist_ok=True)
187189
f.write(f"\nmv *.{self.trajext} {datadir}")
188190

189-
os.chmod(fname, 0o700)
191+
_makeExecutable(fname)
190192

191193
def retrieve(self):
192194
# Nothing to do

jobqueues/sgequeue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def _find_binary(binary):
185185

186186
def _createJobScript(self, fname, workdir, runsh):
187187
from jobqueues.config import template_env
188+
from jobqueues.util import _makeExecutable
188189

189190
workdir = os.path.abspath(workdir)
190191
sentinel = os.path.normpath(os.path.join(workdir, self._sentinel))
@@ -223,7 +224,7 @@ def _createJobScript(self, fname, workdir, runsh):
223224
with open(fname, "w") as f:
224225
f.write(job_str)
225226

226-
os.chmod(fname, 0o700)
227+
_makeExecutable(fname)
227228

228229
def retrieve(self):
229230
# Nothing to do

jobqueues/slurmqueue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def _find_binary(binary, permissive=False):
327327

328328
def _createJobScript(self, fname, workdir, runsh, nvidia_mps=False, commands=None):
329329
from jobqueues.config import template_env
330+
from jobqueues.util import _makeExecutable
330331

331332
# Create a list of lists with the directory of the run.sh and the run.sh itself
332333
runsh = ensurelist(runsh)
@@ -399,7 +400,7 @@ def _createJobScript(self, fname, workdir, runsh, nvidia_mps=False, commands=Non
399400
)
400401
with open(fname, "w") as f:
401402
f.write(job_str)
402-
os.chmod(fname, 0o700)
403+
_makeExecutable(fname)
403404

404405
def retrieve(self):
405406
# Nothing to do

jobqueues/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ def _filterVisibleGPUdevices(devices, _logger):
6262
# Only keep the selected visible devices. intersect of the two lists
6363
devices = [dd for dd in devices if dd in visible_devices]
6464
return devices
65+
66+
67+
def _makeExecutable(fname):
68+
import os
69+
70+
current_mode = os.stat(fname).st_mode
71+
os.chmod(fname, current_mode | 0o100)

tests/test_slurmqueue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def datadir(tmpdir, request):
2323

2424

2525
def _create_execdir(tmpdir, runscript="run.sh"):
26+
from jobqueues.util import _makeExecutable
27+
2628
os.makedirs(tmpdir)
2729
run_sh = os.path.join(tmpdir, runscript)
2830
with open(run_sh, "w") as f:
2931
f.write("sleep 5\n")
30-
os.chmod(run_sh, 0o700)
32+
_makeExecutable(run_sh)
3133
return tmpdir
3234

3335

0 commit comments

Comments
 (0)