title: How to override a global boolean value within a function
body: <pre><code>from playsound import playsound
  import os
  from multiprocessing import Process
  
  def play_song(song_index, loc, song_list):
      global play
      while play:
          try:
              playsound(fr'{loc}\{song_list[song_index]}')
          except Exception as e:
              print(f'Error: {e}')
              break
  
  def controls(input):
      global play
      if input == 'stop':
          play = False
          print('stopped')
  
  play = True
  if __name__ == '__main__':
      while True:
          user = input('Enter folder name [Desktop]:\n&gt;&gt; ')
          loc = fr'{os.environ[&quot;USERPROFILE&quot;]}\Desktop\{user}'
          music_dict = {name: index for name, index in enumerate(os.listdir(loc))}
  
          for index in music_dict:
              print(f'{index}) {music_dict[index]}')
          
          choice = int(input(f'Play song[1-{index}]:\n&gt;&gt; '))
          
          p1 = Process(target=play_song, args=(choice, loc, music_dict))
          p1.start()
  
          control = str(input('&gt;&gt; ')).lower()
  
          p2 = Process(target=controls, args=(control,))
          p2.start()
  
          p1.join()
          p2.join()
  </code></pre>
  <p>When the user inputs 'stop' I want to make <code>play = False</code> to stop the music and repeat the <code>while True</code> loop, I tried using the <code>global</code> keyword but for some reason it is not working.</p>