Skip to content

Commit 6817dbd

Browse files
committedApr 20, 2023
Add conditional installation of sh
1 parent 45f85b9 commit 6817dbd

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed
 

Diff for: ‎hands-on/system_information.ipynb

+11-14
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,25 @@
1212
"cell_type": "markdown",
1313
"metadata": {},
1414
"source": [
15-
"Install `sh` since it doesn't seem to be available."
15+
"Install `sh` if it doesn't seem to be available."
1616
]
1717
},
1818
{
1919
"cell_type": "code",
2020
"execution_count": null,
2121
"metadata": {},
2222
"outputs": [],
23-
"source": [
24-
"!pip install sh"
25-
]
26-
},
27-
{
28-
"cell_type": "code",
29-
"execution_count": 1,
30-
"metadata": {},
31-
"outputs": [],
3223
"source": [
3324
"from datetime import datetime\n",
3425
"import os\n",
3526
"import platform\n",
3627
"import psutil\n",
37-
"import sh\n",
28+
"try:\n",
29+
" import sh\n",
30+
"except ModuleNotFoundError:\n",
31+
" print('installing sh using pip')\n",
32+
" !pip install sh\n",
33+
" import sh\n",
3834
"import sys"
3935
]
4036
},
@@ -228,7 +224,7 @@
228224
"outputs": [],
229225
"source": [
230226
"for process in psutil.process_iter():\n",
231-
" if 'chrome' in process.name():\n",
227+
" if 'python' in process.name():\n",
232228
" cpu_times = process.cpu_times()\n",
233229
" thread_str = f'threads: {process.num_threads()}'\n",
234230
" cpu_str = f'user: {cpu_times.user}, sys: {cpu_times.system}'\n",
@@ -317,7 +313,8 @@
317313
"outputs": [],
318314
"source": [
319315
"for user in psutil.users():\n",
320-
" started = datetime.strftime(datetime.fromtimestamp(user.started), '%Y-%m-%d %H:%M:%S')\n",
316+
" started = datetime.strftime(datetime.fromtimestamp(user.started),\n",
317+
" '%Y-%m-%d %H:%M:%S')\n",
321318
" print(f'{user.name}: {started}')"
322319
]
323320
},
@@ -435,7 +432,7 @@
435432
"name": "python",
436433
"nbconvert_exporter": "python",
437434
"pygments_lexer": "ipython3",
438-
"version": "3.9.6"
435+
"version": "3.11.3"
439436
}
440437
},
441438
"nbformat": 4,

0 commit comments

Comments
 (0)
Please sign in to comment.