Skip to content

Commit 4b6acdc

Browse files
committed
Fix for Google Colab use
1 parent cebc243 commit 4b6acdc

File tree

1 file changed

+95
-11
lines changed

1 file changed

+95
-11
lines changed

system_information.ipynb

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,39 @@
88
"# Information about the system & environment"
99
]
1010
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"Install `sh` since it doesn't seem to be available."
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"!pip install sh"
25+
]
26+
},
1127
{
1228
"cell_type": "code",
1329
"execution_count": null,
1430
"metadata": {
1531
"ExecuteTime": {
16-
"end_time": "2018-11-07T17:08:59.065619Z",
17-
"start_time": "2018-11-07T17:08:59.058695Z"
32+
"end_time": "2018-11-15T06:15:12.468350Z",
33+
"start_time": "2018-11-15T06:15:12.456515Z"
1834
}
1935
},
2036
"outputs": [],
2137
"source": [
38+
"from datetime import datetime\n",
2239
"import os\n",
2340
"import platform\n",
24-
"import sys\n",
25-
"\n",
26-
"import psutil"
41+
"import psutil\n",
42+
"import sh\n",
43+
"import sys"
2744
]
2845
},
2946
{
@@ -317,16 +334,16 @@
317334
"execution_count": null,
318335
"metadata": {
319336
"ExecuteTime": {
320-
"end_time": "2018-11-12T12:59:13.616730Z",
321-
"start_time": "2018-11-12T12:59:13.383013Z"
337+
"end_time": "2018-11-15T05:53:15.410000Z",
338+
"start_time": "2018-11-15T05:53:15.293369Z"
322339
},
323340
"hidden": true,
324341
"scrolled": false
325342
},
326343
"outputs": [],
327344
"source": [
328345
"for process in psutil.process_iter():\n",
329-
" if 'gjb' in process.username():\n",
346+
" if 'bash' in process.name():\n",
330347
" cpu_times = process.cpu_times()\n",
331348
" thread_str = f'threads: {process.num_threads()}'\n",
332349
" cpu_str = f'user: {cpu_times.user}, sys: {cpu_times.system}'\n",
@@ -373,14 +390,46 @@
373390
"execution_count": null,
374391
"metadata": {
375392
"ExecuteTime": {
376-
"end_time": "2018-11-12T13:55:42.525140Z",
377-
"start_time": "2018-11-12T13:55:42.420751Z"
393+
"end_time": "2018-11-15T06:05:47.011309Z",
394+
"start_time": "2018-11-15T06:05:46.973339Z"
395+
},
396+
"hidden": true
397+
},
398+
"outputs": [],
399+
"source": [
400+
"sleep = sh.sleep(120, _bg=True)"
401+
]
402+
},
403+
{
404+
"cell_type": "code",
405+
"execution_count": null,
406+
"metadata": {
407+
"ExecuteTime": {
408+
"end_time": "2018-11-15T06:05:47.632555Z",
409+
"start_time": "2018-11-15T06:05:47.560416Z"
410+
},
411+
"hidden": true
412+
},
413+
"outputs": [],
414+
"source": [
415+
"for process in psutil.process_iter():\n",
416+
" if 'sleep' in process.name():\n",
417+
" print(process)"
418+
]
419+
},
420+
{
421+
"cell_type": "code",
422+
"execution_count": null,
423+
"metadata": {
424+
"ExecuteTime": {
425+
"end_time": "2018-11-15T06:06:13.213564Z",
426+
"start_time": "2018-11-15T06:06:13.055494Z"
378427
},
379428
"hidden": true
380429
},
381430
"outputs": [],
382431
"source": [
383-
"name = 'zeal'\n",
432+
"name = 'sleep'\n",
384433
"killed_pids = []\n",
385434
"for process in psutil.process_iter():\n",
386435
" if name == process.name():\n",
@@ -390,6 +439,41 @@
390439
"print('killed: ', ', '.join(map(str, killed_pids)))"
391440
]
392441
},
442+
{
443+
"cell_type": "markdown",
444+
"metadata": {
445+
"heading_collapsed": true
446+
},
447+
"source": [
448+
"## Users"
449+
]
450+
},
451+
{
452+
"cell_type": "markdown",
453+
"metadata": {
454+
"hidden": true
455+
},
456+
"source": [
457+
"You can retrieve information on the users on the system as well."
458+
]
459+
},
460+
{
461+
"cell_type": "code",
462+
"execution_count": null,
463+
"metadata": {
464+
"ExecuteTime": {
465+
"end_time": "2018-11-15T06:17:52.182805Z",
466+
"start_time": "2018-11-15T06:17:52.173132Z"
467+
},
468+
"hidden": true
469+
},
470+
"outputs": [],
471+
"source": [
472+
"for user in psutil.users():\n",
473+
" started = datetime.strftime(datetime.fromtimestamp(user.started), '%Y-%m-%d %H:%M:%S')\n",
474+
" print(f'{user.name}: {started}')"
475+
]
476+
},
393477
{
394478
"cell_type": "markdown",
395479
"metadata": {

0 commit comments

Comments
 (0)