: ( ), - - - . python 2.7 OSX 10.9
mplayer , , q, :
import shlex
import time
from subprocess import Popen, PIPE
cmd = shlex.split("mplayer http://www.swissradio.ch/streams/6034.m3u")
p = Popen(cmd, stdin=PIPE)
time.sleep(5)
p.communicate(b'q')
mplayer ; 5 ; mplayer . ( , python script).
p.kill(), p.terminate(), p.send_signal(signal.SIGINT) (Ctrl + C). p.kill() , . : p.kill() , , stdout=PIPE, Python script p.stdout.read(), mplayer , , , p.terminate(), p.send_signal(signal.SIGINT) - mplayer . , , reset.
Python, ? PIPE?
stdin=PIPE p.terminate(); p.wait() p.communicate(b'q').
stdin=PIPE, : sys.stdin, p.stdin , -. , mplayer , sys.stdin. : p.stdin.write(c) ( bufsize=0, Python. mplayer stdin, ).
. timeout, threading.Timer(5, p.stdin.write, [b'q']).start() select.select sys.stdin .
, -, raw_input, , ?
raw_input() mplayer, , mplayer .