Now that we have a grasp on the main reactive programming concepts, we can implement a sample application. In this subsection, we will implement a monitor that will give us real-time information about our CPU usage and is capable of detecting spikes.
As a first step, let's implement a data source. We will use the psutil module that provides a function, psutil.cpu_percent, that returns the latest available CPU usage as a percent (and doesn't block):
import psutil psutil.cpu_percent() # Result: 9.7
Since we are developing a monitor, we would like to sample this information over a few time intervals. To accomplish this we can use the familiar ...