Thanks for introducing me to multiprossesing. I finally got it working. Not sure if it's the best way of doing it but here's my final code.
import RPi.GPIO as GPIO import time, os, signal, playsong from multiprocessing import Process from subprocess import check_output buttonpin = 23 #GPIO23 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(buttonpin, GPIO.IN, pull_up_down=GPIO.PUD_UP) m_pid = 0 def play(): '''play music from playsong.py ''' playsong.song() def get_pid(): '''gets mplayer's actual pid''' global m_pid m_pid = int(check_output(["pidof","-s","mplayer"])) print "mplayer's pid: ", m_pid def kill_pid(pid): '''used to kill mplayer's pid''' os.kill(pid, signal.SIGKILL) def button(): '''check if button is pressed''' while True: input_state = GPIO.input(buttonpin) if input_state == False: print 'on' time.sleep(0.3) #debounce kill_pid(m_pid) if __name__ == '__main__': p1 = Process(target=play) p1.start() p2 = Process(target=button) p2.start() p3 = Process(target=get_pid) p3.start() p1.join() p2.join() p3.join()