Bug: Number of processes must be at least 1
I'm running Swing Music in a docker container in a VPS with 1 vCore.
After running a scan of my files, I get this:
Exception in thread Thread-3 (index_everything):
Traceback (most recent call last):
File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.11/threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "/app/swingmusic/app/lib/index.py", line 45, in index_everything
return IndexEverything()
^^^^^^^^^^^^^^^^^
File "/app/swingmusic/app/lib/index.py", line 21, in __init__
IndexTracks()
File "/app/swingmusic/app/lib/tagger.py", line 58, in __init__
self.tag_untagged(untagged)
File "/app/swingmusic/app/lib/tagger.py", line 135, in tag_untagged
with Pool(processes=math.floor(cpu_count() / 2)) as pool:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/multiprocessing/context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/multiprocessing/pool.py", line 205, in __init__
raise ValueError("Number of processes must be at least 1")
ValueError: Number of processes must be at least 1
What can I do in order to solve? If you need additional info, ask please! Thanks
Hi @andrea3x
The Swing Music code tries to use half the number of CPU cores available on the system. In case of decimals, the result of (cpu_count / 2) if floored. In this case it becomes 0 which causes the error.
math.floor(cpu_count() / 2)
I'll fix this for the next commit. The fix will be available in the next release. If you want to get it sooner, you can run Swing Music from source.
Thank you.
@cwilvx thank you!
In the whiletime, with the help of gpt (I'm still not familiar with python and threads), I've tried to solve the issue.
I patched both app/lib/tagger.py and app/lib/populate.py using max():
tagger.py:
# Use max to ensure at least 1 process is used.
num_processes = max(1, math.floor(cpu_count() / 2))
# Create process pool with worker function
with Pool(processes=num_processes) as pool:
Similarly, I edited populate.py.
It seems to work! I hope this can help you! Thank you
Clicking on Quick Scan gives me the following logs. I think it's related to the 1-core thing, but if I'm wrong, I'll submit a new issue.
INFO|Reading files ...
0%| |0/0
0 new files indexed
Done
Loading tracks... Loading albums... Done!
Loading artists... Done!
INFO|Extracting track images ...
0%| |0/3
Exception in thread Thread-9 (index_everything):
Traceback (most recent call last):
File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.11/threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "/app/swingmusic/app/lib/index.py", line 45, in index_everything
return IndexEverything()
^^^^^^^^^^^^^^^^^
File "/app/swingmusic/app/lib/index.py", line 39, in __init__
CordinateMedia(instance_key=str(time()))
File "/app/swingmusic/app/lib/populate.py", line 31, in __init__
ProcessTrackThumbnails()
File "/app/swingmusic/app/lib/populate.py", line 132, in __init__
self.extract(albums)
File "/app/swingmusic/app/lib/populate.py", line 102, in extract
results = list(
^^^^^
File "/usr/local/lib/python3.11/site-packages/tqdm/std.py", line 1181, in __iter__
for obj in iterable:
File "/usr/local/lib/python3.11/concurrent/futures/process.py", line 620, in _chain_from_iterable_of_lists
for element in iterable:
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
And if patching better (and not only with gpt 😂) is the solution, I'll wait until the next release before opening issues related to threading! Thanks again
@andrea3x
Could you let me know if this issue was fixed?
Hi @cwilvx !
Sorry for forgetting to answer. In a few days I'll try to upload stuff to the server, and I let you know! Thank you
Hi @cwilvx ! I think this is solved. I tried uploading multiple songs but no error was thrown. Thank you!