Wool
Wool

Reputation: 17

Running part of script whilst other part is running -python

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

Answers (2)

Wool
Wool

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

Shri Ram K Raja
Shri Ram K Raja

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

Related Questions