Reputation: 17
How am I able to run my line of code in the background whilst other part is running.I only want to run it from IDLE without the CLI. I want it something like this. Thanks in advance.
from playsound import playsound
playsound('The Music which i want run in the background')
#The code i want to run in the foreground
Upvotes: 0
Views: 83
Reputation: 17
from threading import Thread
Thread(target=playsound, args=('\dir\to\music')).start()
'Concurrent code'
_________________
or you can simply:
playsound('\dir\to\music', 0)
Upvotes: 0
Reputation: 101
You can use Multiprocessing library to achieve this.
from playsound import playsound
from multiprocessing import Process
process_for_sound = Process(target=playsound, args=('The Music which i want run in the background',))
process_for_sound.start()
process_for_sound.join()
#The code you want to run in the concurrently.
Upvotes: 1