1 Applying Changes
1 Applying Changes
Command:
1
$ cat cpu_usage.py
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
import psutil
def check_cpu_usage(percent):
usage = psutil.cpu_percent()
return usage < percent
if not check_cpu_usage(75):
print("ERROR! CPU is overloaded")
else:
print("Everything ok")
Command:
1
2
$ diff -u cpu_usage.py cpu_usage_new.py > cpu_usage.diff
$ cat cpu_usage.diff
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--- cpu_usage.py 2019-06-23 08:16:04.666457429 -0700
+++ cpu_usage_fixed.py 2019-06-23 08:15:37.534370071 -0700
@@ -2,7 +2,8 @@
import psutil
def check_cpu_usage(percent):
- usage = psutil.cpu_percent()
+ usage = psutil.cpu_percent(1)
+ print("DEBUG: usage: {}".format(usage))
return usage < percent
if not check_cpu_usage(75):
Command:
1
$ patch cpu_usage.py < cpu_usage.diff
Code output:
1
patching file cpu_usage.py
Command:
1
$ cat cpu_usage.py
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3
import psutil
def check_cpu_usage(percent):
usage = psutil.cpu_percent(1)
print("DEBUG: usage: {}".format(usage))
return usage < percent
if not check_cpu_usage(75):
print("ERROR! CPU is overloaded")
else:
print("Everything ok")
This post is licensed under CC BY 4.0 by the author.