Skip to content

Instantly share code, notes, and snippets.

@Muffo Muffo/
Last active Aug 29, 2015

What would you like to do?
CPU usage with and psutil
__author__ = 'muffo'
from bottle import route, response, run
from time import sleep
from psutil import cpu_percent
from json import dumps
import thread
cpu = None
def update_cpu(delay):
global cpu
while True:
cpu = cpu_percent(interval=None, percpu=True)
print "CPU Thread:", cpu
def hello():
global cpu
response.content_type = 'application/json'
return dumps({"cpu": cpu})
thread.start_new_thread(update_cpu, (1, ))
run(host='localhost', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.