1

The relevant code is actually from a separate thread.

Here it is anyway

import multiprocessing
from playsound import playsound

p = multiprocessing.Process(target=playsound, args=("file.mp3",))
p.start()
input("press ENTER to stop playback")
p.terminate()

When I run this exact code, I get the following error:

Traceback (most recent call last):
  File "/Users/omit/Developer/omit/main2.py", line 22, in <module>
    p2 = multiprocessing.Process(printStatus)
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 82, in __init__
    assert group is None, 'group argument must be None for now'
AssertionError: group argument must be None for now
(yt-proj) omit@omit-Air youtube proj % /opt/homebrew/bin/python3 "/Users/omit/Developer/omit/main2.py"
Traceback (most recent call last):
  File "/Users/omit/Developer/omit/main2.py", line 22, in <module>
    p2 = multiprocessing.Process(printStatus)
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 82, in __init__
    assert group is None, 'group argument must be None for now'
AssertionError: group argument must be None for now

What could be the problem?

soy-ish
  • 35
  • 4
  • Can you add a minimum reproducible example? Your code doesn't have a problem besides not checking if you are top level. Your error, on the other hand, shows a variable that is not in your code. – 2pichar Apr 26 '22 at 02:45
  • @2pichar My code looks exactly like the code above, except it uses a different mp3 file. – soy-ish Apr 26 '22 at 02:50
  • then what is this `p2` variable? – 2pichar Apr 26 '22 at 02:50
  • Right - completely missed that. You're right that I had a p2 variable in there somewhere – soy-ish Apr 26 '22 at 02:57

2 Answers2

2

The code to start the multiprocessing must never be "top level". It must only be run if this is the main thread.

def main():
    p = multiprocessing.Process(target=playsound, args=("file.mp3",))
    p.start()
    input("press ENTER to stop playback")
    p.terminate()

if __name__ == "__main__":
    main()
Frank Yellin
  • 9,127
  • 1
  • 12
  • 22
1

Your problem, as seen in your error message is in the p2 variable. You are creating it like this:

p2 = multiprocessing.Process(printStatus)

That is a problem because the first positional argument is the group parameter. You need to change it to this:

p2 = multiprocessing.Process(target=printStatus)

Here are the python docs for multiprocessing.Process.

The relevant paragraph (emphasis mine):

class multiprocessing.Process(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)
Process objects represent activity that is run in a separate process. The Process class has equivalents of all the methods of threading.Thread.
The constructor should always be called with keyword arguments. group should always be None; it exists solely for compatibility with threading.Thread. target is the callable object to be invoked by the run() method.

As shown above, your problem is coming from trying to create a Process object without using keyword arguments, and it is assigning something to the group parameter.

2pichar
  • 1,348
  • 4
  • 17