Skip to content

Instantly share code, notes, and snippets.

@brianpeiris
Last active December 8, 2016 12:35
Show Gist options
  • Save brianpeiris/8708cdf8812d656fa418 to your computer and use it in GitHub Desktop.
Save brianpeiris/8708cdf8812d656fa418 to your computer and use it in GitHub Desktop.
A python program (for windows) that plays tones based on disk activity
import time
import psutil
import winsound
last_disk_time = None
last_time = None
while (True):
curr_time = time.time()
counters = psutil.disk_io_counters()
read_time = counters.read_time
write_time = counters.write_time
curr_disk_time = read_time + write_time
if last_disk_time is not None:
ddisk = curr_disk_time - last_disk_time
dtime = curr_time - last_time
disk_rate = ddisk / dtime
diff = 500 + round(disk_rate / 3000)
print('{0: > 010n}, {1}'.format(round(disk_rate), diff))
if diff > 550:
winsound.Beep(diff, 200)
else:
time.sleep(0.2)
last_disk_time = curr_disk_time
last_time = curr_time
time.sleep(0.05)
@patentfox
Copy link

Hi Brian
Can you please explain how did you choose these constants - 500, 3000, 550, 200 in your code above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment