Skip to content

Commit 84ef248

Browse files
authored
Merge pull request refnx#880 from andyfaff/numprocs
MAINT: look for a NUM_PROCS envvar to limit parallelisation during sa…
2 parents e627d46 + 53de8c8 commit 84ef248

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

refnx/_lib/util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,20 @@ def __init__(self, pool=-1, context=None):
238238
self.pool = pool
239239
self._mapfunc = self.pool
240240
else:
241-
# user supplies a number
241+
# Always respect a user supplied number.
242242
if int(pool) == -1:
243+
# The default is to use as many processes as possible.
244+
# See if the user has specified a limit via an environment
245+
# variable though.
246+
# If there's no environment variable then num_procs = None
247+
# and creating the Pool will use as many processes as
248+
# possible.
249+
num_procs = _os.getenv("NUM_PROCS")
250+
if num_procs is not None:
251+
num_procs = int(num_procs)
252+
243253
# use as many processors as possible
244-
self.pool = ctx.Pool()
254+
self.pool = ctx.Pool(num_procs)
245255
self._mapfunc = self.pool.map
246256
self._own_pool = True
247257
elif int(pool) in [0, 1]:

0 commit comments

Comments
 (0)