Updated M module1.ipynb
This commit is contained in:
parent
61a0288bca
commit
cf92d8fd47
123
module1.ipynb
123
module1.ipynb
@ -154,19 +154,136 @@
|
||||
"\n",
|
||||
" return True"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"This reading contains the code used in the instructional videos from [**Applying Changes** <svg aria-labelledby=\"cds-react-aria2448342354-:r9g:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria2448342354-:r9g:\"><title id=\"cds-react-aria2448342354-:r9g:-title\">Opens in a new tab</title><path d=\"M4.5 17c-.412 0-.766-.147-1.06-.44A1.445 1.445 0 013 15.5v-11c0-.412.147-.766.44-1.06.294-.293.648-.44 1.06-.44h4.75c.213 0 .39.071.534.214a.72.72 0 01.216.532c0 .21-.072.39-.216.535a.72.72 0 01-.534.219H4.5v11h11v-4.75c0-.213.072-.39.214-.534a.72.72 0 01.532-.216c.21 0 .39.072.535.216a.72.72 0 01.219.534v4.75c0 .412-.147.766-.44 1.06-.294.293-.647.44-1.06.44h-11zm11-11.438L8.583 12.48a.681.681 0 01-.52.219.758.758 0 01-.521-.24.729.729 0 010-1.062L14.438 4.5H12.75a.728.728 0 01-.534-.214.72.72 0 01-.216-.532c0-.21.072-.39.216-.535A.72.72 0 0112.75 3h3.5c.212 0 .39.072.534.216A.726.726 0 0117 3.75v3.5c0 .213-.072.39-.214.534a.72.72 0 01-.532.216.734.734 0 01-.535-.216.72.72 0 01-.219-.534V5.562z\" fill=\"currentColor\" data-darkreader-inline-fill=\"\" style=\"--darkreader-inline-fill: currentColor;\"></path></svg>](https://www.coursera.org/learn/introduction-git-github/lecture/qIzdp/applying-changes).\n",
|
||||
"\n",
|
||||
"## Introduction\n",
|
||||
"\n",
|
||||
"This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n",
|
||||
"\n",
|
||||
"You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"cat cpu\\_usage.py \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"cat cpu\\_usage.py \n",
|
||||
"\n",
|
||||
"**Code output:**\n",
|
||||
"\n",
|
||||
"#!/usr/bin/env python3\n",
|
||||
"\n",
|
||||
"import psutil\n",
|
||||
"\n",
|
||||
"def check\\_cpu\\_usage(percent):\n",
|
||||
"\n",
|
||||
" usage = psutil.cpu\\_percent()\n",
|
||||
"\n",
|
||||
" return usage < percent\n",
|
||||
"\n",
|
||||
"if not check\\_cpu\\_usage(75):\n",
|
||||
"\n",
|
||||
" print(\"ERROR! CPU is overloaded\")\n",
|
||||
"\n",
|
||||
"else:\n",
|
||||
"\n",
|
||||
" print(\"Everything ok\")\n",
|
||||
"\n",
|
||||
"1\n",
|
||||
"\n",
|
||||
"cat cpu\\_usage.diff \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Code output:**\n",
|
||||
"\n",
|
||||
"\\--- cpu\\_usage.py 2019-06-23 08:16:04.666457429 -0700\n",
|
||||
"\n",
|
||||
"+++ cpu\\_usage\\_fixed.py 2019-06-23 08:15:37.534370071 -0700\n",
|
||||
"\n",
|
||||
"@@ -2,7 +2,8 @@\n",
|
||||
"\n",
|
||||
" import psutil\n",
|
||||
"\n",
|
||||
" def check\\_cpu\\_usage(percent):\n",
|
||||
"\n",
|
||||
"\\- usage = psutil.cpu\\_percent()\n",
|
||||
"\n",
|
||||
"+ usage = psutil.cpu\\_percent(1)\n",
|
||||
"\n",
|
||||
"+ print(\"DEBUG: usage: {}\".format(usage))\n",
|
||||
"\n",
|
||||
" return usage < percent\n",
|
||||
"\n",
|
||||
" if not check\\_cpu\\_usage(75):\n",
|
||||
"\n",
|
||||
"1\n",
|
||||
"\n",
|
||||
"patch cpu\\_usage.py < cpu\\_usage.diff \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Code output:**\n",
|
||||
"\n",
|
||||
"patching file cpu\\_usage.py\n",
|
||||
"\n",
|
||||
"1\n",
|
||||
"\n",
|
||||
"cat cpu\\_usage.py \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Code output:**\n",
|
||||
"\n",
|
||||
"#!/usr/bin/env python3\n",
|
||||
"\n",
|
||||
"import psutil\n",
|
||||
"\n",
|
||||
"def check\\_cpu\\_usage(percent):\n",
|
||||
"\n",
|
||||
" usage = psutil.cpu\\_percent(1)\n",
|
||||
"\n",
|
||||
" print(\"DEBUG: usage: {}\".format(usage))\n",
|
||||
"\n",
|
||||
" return usage < percent\n",
|
||||
"\n",
|
||||
"if not check\\_cpu\\_usage(75):\n",
|
||||
"\n",
|
||||
" print(\"ERROR! CPU is overloaded\")\n",
|
||||
"\n",
|
||||
"else:\n",
|
||||
"\n",
|
||||
" print(\"Everything ok\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"version": "3.12.3"
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.13.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user