title: Pulseaudio and sudo in Python
body: <p>I am running a script that works on sockets.. It requires sudo to run..
  however,
  Inside the script i call another script that requires not to be run as sudo</p>
  
  <p>here is the code:</p>
  
  <pre><code>import subprocess
  import socket
  s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  #s.settimeout(5.0)
  host='192.168.1.148'
  port=1022
  s.bind((host, port))
  s.listen(5)
  while True:
      c, addr = s.accept()
      subprocess.call("python bluetooth2.py",shell=True)
      print 'got connection from',addr
      c.send('Thank you for connecting')
      #c.settimeout(5.0)
      c.recv(1022)
      c.close()
  </code></pre>
  
  <p><code>bluetooth2.py</code> runs pulseaudio which is run as root for some reason and doesn't work. any help greatly appreciated!</p>
  
  <p>Here is what the bluetooth2.py script looks like for reference (the one that is calling on pulseaudio)</p>
  
  <pre><code>import time
  import pexpect
  from sh import bluetoothctl
  import subprocess
  mac = "C8:84:47:26:E6:3C"
  print ("stuck here")
  #bluetoothctl("connect", mac)
  
  def connect():
      child = pexpect.spawn('bluetoothctl')
      child.sendline('power on')
      child.sendline('agent on')
      child.sendline('default-agent')
      child.sendline('pair C8:84:47:26:E6:3C')
      time.sleep(1)
      child.sendline('trust C8:84:47:26:E6:3C')
      time.sleep(1)
      child.sendline('connect C8:84:47:26:E6:3C')
      print("connecting...")
      time.sleep(5)
      subprocess.call("pulseaudio --start",shell=True)
      subprocess.call("pacmd set-default-sink
      bluez_sink.C8_84_47_26_E6_3C",shell=True)
      subprocess.call("aplay /home/pi/bleep_01.wav", shell=True)
  </code></pre>