Add an option allowing use without a multiprocessing pool...

...this allows spleeter itself to be run asynchronously from another
process using multiprocessing, which otherwise fails with "daemonic
processes are not allowed to have children"
This commit is contained in:
valrus
2020-01-11 14:50:37 -08:00
parent fc1e3d9a2f
commit aff7f83a13

View File

@@ -35,7 +35,7 @@ __license__ = 'MIT License'
class Separator(object):
""" A wrapper class for performing separation. """
def __init__(self, params_descriptor, MWF=False):
def __init__(self, params_descriptor, MWF=False, multiprocess=True):
""" Default constructor.
:param params_descriptor: Descriptor for TF params to be used.
@@ -45,7 +45,7 @@ class Separator(object):
self._sample_rate = self._params['sample_rate']
self._MWF = MWF
self._predictor = None
self._pool = Pool()
self._pool = Pool() if multiprocess else None
self._tasks = []
def _get_predictor(self):
@@ -133,6 +133,7 @@ class Separator(object):
f'Separated source path conflict : {path},'
'please check your filename format'))
generated.append(path)
if self._pool:
task = self._pool.apply_async(audio_adapter.save, (
path,
data,
@@ -140,5 +141,7 @@ class Separator(object):
codec,
bitrate))
self._tasks.append(task)
if synchronous:
else:
audio_adapter.save(path, data, self._sample_rate, codec, bitrate)
if synchronous and self._pool:
self.join()