|
12 | 12 | "cell_type": "markdown",
|
13 | 13 | "metadata": {},
|
14 | 14 | "source": [
|
15 |
| - "Install `sh` since it doesn't seem to be available." |
| 15 | + "Install `sh` if it doesn't seem to be available." |
16 | 16 | ]
|
17 | 17 | },
|
18 | 18 | {
|
19 | 19 | "cell_type": "code",
|
20 | 20 | "execution_count": null,
|
21 | 21 | "metadata": {},
|
22 | 22 | "outputs": [],
|
23 |
| - "source": [ |
24 |
| - "!pip install sh" |
25 |
| - ] |
26 |
| - }, |
27 |
| - { |
28 |
| - "cell_type": "code", |
29 |
| - "execution_count": 1, |
30 |
| - "metadata": {}, |
31 |
| - "outputs": [], |
32 | 23 | "source": [
|
33 | 24 | "from datetime import datetime\n",
|
34 | 25 | "import os\n",
|
35 | 26 | "import platform\n",
|
36 | 27 | "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", |
38 | 34 | "import sys"
|
39 | 35 | ]
|
40 | 36 | },
|
|
228 | 224 | "outputs": [],
|
229 | 225 | "source": [
|
230 | 226 | "for process in psutil.process_iter():\n",
|
231 |
| - " if 'chrome' in process.name():\n", |
| 227 | + " if 'python' in process.name():\n", |
232 | 228 | " cpu_times = process.cpu_times()\n",
|
233 | 229 | " thread_str = f'threads: {process.num_threads()}'\n",
|
234 | 230 | " cpu_str = f'user: {cpu_times.user}, sys: {cpu_times.system}'\n",
|
|
317 | 313 | "outputs": [],
|
318 | 314 | "source": [
|
319 | 315 | "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", |
321 | 318 | " print(f'{user.name}: {started}')"
|
322 | 319 | ]
|
323 | 320 | },
|
|
435 | 432 | "name": "python",
|
436 | 433 | "nbconvert_exporter": "python",
|
437 | 434 | "pygments_lexer": "ipython3",
|
438 |
| - "version": "3.9.6" |
| 435 | + "version": "3.11.3" |
439 | 436 | }
|
440 | 437 | },
|
441 | 438 | "nbformat": 4,
|
|
0 commit comments