title: Is battery plugged or not in real time(on Linux), need quick fix in code
body: <p>I have a weird code which is intended to perform as follow: When the code is running it should check if the battery is plugged or not. if that's the case then use the alarm sound. (using Linux)</p>
  
  <p><strong>The problem:</strong> in while loop variable plugged value never changes.
  It does not matter if the battery is plugged or not. When I am charging the laptop and start the program the alarm goes on <strong>but if I unplugged it nothing changes.</strong></p>
  
  <p>I have tried time.sleep() method thought program needed some time to update the current plugged value but nothing promising so far...</p>
  
  <pre class="lang-py prettyprint-override"><code>import psutil
  import os
  import time
  
  battery = psutil.sensors_battery()
  plugged = battery.power_plugged
  
  while plugged:
      os.system('aplay klax_11.wav')
      time.sleep(5)
      plugged = battery.power_plugged
  </code></pre>
  
  <p>Desirable behaviour is next: While loop should break when I unplugged the device from a power source.</p>