2002 lines
87 KiB
Plaintext
2002 lines
87 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "b644e953-5404-4364-ad7d-5da1266490aa",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"%run live_coding/lecture05.py"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "3f7aa5ee-bed9-4621-8377-c46f515cfe89",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Variable Type Data/Info\n",
|
|
"------------------------------------\n",
|
|
"div function <function div at 0x107382b60>\n",
|
|
"logging module <module 'logging' from '/<...>.12/logging/__init__.py'>\n",
|
|
"test_logging function <function test_logging at 0x107381c60>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"whos"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "81cff98a-f524-472c-bdc3-21a4d1a3208a",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"\u001b[31mSignature:\u001b[39m test_logging()\n",
|
|
"\u001b[31mSource:\u001b[39m \n",
|
|
"\u001b[38;5;28;01mdef\u001b[39;00m test_logging():\n",
|
|
" \u001b[33m\"\"\"Function to test logging levels.\"\"\"\u001b[39m\n",
|
|
" print(\u001b[33m\"This always prints.\"\u001b[39m)\n",
|
|
" logging.critical(\u001b[33m\"Critical Message\"\u001b[39m)\n",
|
|
" logging.error(\u001b[33m\"Error Message\"\u001b[39m)\n",
|
|
" logging.warning(\u001b[33m\"Warning Message\"\u001b[39m)\n",
|
|
" logging.info(\u001b[33m\"Info Message\"\u001b[39m)\n",
|
|
" logging.debug(\u001b[33m\"Debug Message\"\u001b[39m)\n",
|
|
"\u001b[31mFile:\u001b[39m ~/Documents/Diller_Digital_SWNG/live_coding/lecture05.py\n",
|
|
"\u001b[31mType:\u001b[39m function"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"test_logging??"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "ee125cd5-3b98-47a5-8161-906d9d480d2b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"CRITICAL:root:Critical Message\n",
|
|
"ERROR:root:Error Message\n",
|
|
"WARNING:root:Warning Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "69c1ff9e-a066-4254-be3a-b444f8709e2d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import logging\n",
|
|
"logging.basicConfig(level=logging.INFO, force=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "da245cec-e316-4a76-954b-ac90dbc76793",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"CRITICAL:root:Critical Message\n",
|
|
"ERROR:root:Error Message\n",
|
|
"WARNING:root:Warning Message\n",
|
|
"INFO:root:Info Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "2c5d81b7-e2d2-497a-95b1-0cb1b2a3f8ab",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"logger = logging.getLogger()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "c2f04f99-120a-43c2-9f7e-7a3110da35b1",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<RootLogger root (INFO)>"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"logger"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "fbdb085d-2af9-4ec8-865e-de136b236515",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"CRITICAL:root:Critical Message\n",
|
|
"ERROR:root:Error Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.setLevel(logging.ERROR)\n",
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "85620e6f-2523-4095-8ab4-3a9282bad5e4",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"CRITICAL:root:Critical Message\n",
|
|
"ERROR:root:Error Message\n",
|
|
"WARNING:root:Warning Message\n",
|
|
"INFO:root:Info Message\n",
|
|
"DEBUG:root:Debug Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.setLevel(logging.NOTSET)\n",
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "82e1258a-8d14-4522-83cc-f8a742b4b6a0",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"INFO:root:Hello my name is Inigo\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.info(\"Hello my name is Inigo\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"id": "a114ac1a-8400-4f5e-afe6-d08086845a0b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[<StreamHandler stderr (NOTSET)>]"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.handlers"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"id": "369503bc-095b-486b-a9c4-fd61f8be36dc",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<StreamHandler stderr (NOTSET)>"
|
|
]
|
|
},
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"h = logger.handlers[0]\n",
|
|
"h"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"id": "4a32033e-d96b-46a5-b99e-d625e397e5b2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"h.setLevel(logging.ERROR)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"id": "9e49a2d8-83ed-4f99-b87e-a2fe1eb108f3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"logger.info(\"Hello\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"id": "2383ecfe-9921-4f36-975a-5c2ef5accc42",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<logging.Formatter at 0x107065640>"
|
|
]
|
|
},
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"h.formatter"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"id": "80b8e630-ee86-4d4f-82a7-634530013f62",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"f = h.formatter"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"id": "b105177b-28c3-445e-a8e8-8093f8752abd",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2025-10-23 10:33:28,982:<module>() - Help Help\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"f2 = logging.Formatter('%(asctime)s:%(funcName)s() - %(message)s')\n",
|
|
"h.setFormatter(f2)\n",
|
|
"logger.critical(\"Help Help\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"id": "a8fc2123-1543-4fbb-84dd-12ef77059a60",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2025-10-23 10:34:09,665:test_logging() - Critical Message\n",
|
|
"2025-10-23 10:34:09,667:test_logging() - Error Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"id": "990f20dc-b033-40e3-a6a0-d43aa3c9f980",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"CRITICAL:root:Critical Message\n",
|
|
"ERROR:root:Error Message\n",
|
|
"WARNING:root:Warning Message\n",
|
|
"INFO:root:Info Message\n",
|
|
"DEBUG:root:Debug Message\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This always prints.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logging.basicConfig(force=True)\n",
|
|
"test_logging()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"id": "1c5f9550-1115-411c-875f-5a799856956f",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'__main__'"
|
|
]
|
|
},
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"__name__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"id": "ba93a4d1-f02f-40a8-8a81-71a53f3382d5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"logger = logging.getLogger(__name__)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 28,
|
|
"id": "49d05cb0-6346-4b18-a5b2-fb7ce990f99c",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"WARNING:__main__:Hi\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.warning(\"Hi\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"id": "02558566-5c42-4951-af32-f27025e00cdf",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import sys\n",
|
|
"h2 = logging.StreamHandler(sys.stdout)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 30,
|
|
"id": "bd9f231f-3fa0-4979-890a-6bb40be64c0f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"logger = logging.getLogger(__name__)\n",
|
|
"logger.handlers.append(h2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"id": "7b0a7c8f-f3dd-42ef-aa82-b98ae5b592fb",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Hi\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ERROR:__main__:Hi\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger.error(\"Hi\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d38c51cc-df40-4d45-a7f8-4fe0d36ab3f9",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Lecture 6 - Profiling and Debugging\n",
|
|
"`demo/Software_Engineering/citation_network`"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "3af3737f-66d2-4270-8759-7ce4e1b56435",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%cd demo/Software_Engineering/citation_network/"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"id": "427ed209-89d1-43de-8ca3-cf995ee68769",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0.0% 0\n",
|
|
" 10.0% 0\n",
|
|
" 20.0% 1\n",
|
|
" 30.0% 1\n",
|
|
" 40.0% 3\n",
|
|
" 50.0% 4\n",
|
|
" 60.0% 6\n",
|
|
" 70.0% 9\n",
|
|
" 80.0% 15\n",
|
|
" 90.0% 29\n",
|
|
"100.0% 2414\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
" 1101027 function calls (1101014 primitive calls) in 0.480 seconds\n",
|
|
"\n",
|
|
" Ordered by: internal time\n",
|
|
"\n",
|
|
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
|
|
" 1 0.200 0.200 0.218 0.218 citation_network_slow.py:53(build_index)\n",
|
|
" 3 0.084 0.028 0.605 0.202 selectors.py:558(select)\n",
|
|
" 1 0.079 0.079 0.111 0.111 citation_network_slow.py:37(load_citations)\n",
|
|
" 705636 0.034 0.000 0.034 0.000 {method 'append' of 'list' objects}\n",
|
|
" 352809 0.029 0.000 0.029 0.000 {method 'split' of 'str' objects}\n",
|
|
" 3 0.025 0.008 0.514 0.171 {method 'control' of 'select.kqueue' objects}\n",
|
|
" 1 0.013 0.013 0.351 0.351 citation_network_slow.py:1(<module>)\n",
|
|
" 1 0.004 0.004 0.004 0.004 {built-in method builtins.sorted}\n",
|
|
" 1 0.002 0.002 0.003 0.003 citation_network_slow.py:74(citation_counts)\n",
|
|
" 1158 0.002 0.000 0.003 0.000 ipkernel.py:797(_clean_thread_parent_frames)\n",
|
|
" 1 0.001 0.001 0.001 0.001 {built-in method builtins.compile}\n",
|
|
" 27801 0.001 0.000 0.001 0.000 {built-in method builtins.len}\n",
|
|
" 579 0.001 0.000 0.001 0.000 threading.py:1535(enumerate)\n",
|
|
" 5790 0.001 0.000 0.001 0.000 threading.py:1198(ident)\n",
|
|
" 682 0.000 0.000 0.000 0.000 {built-in method _codecs.ascii_decode}\n",
|
|
" 1 0.000 0.000 0.338 0.338 citation_network_slow.py:118(main)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {built-in method _io.open}\n",
|
|
" 3 0.000 0.000 0.606 0.202 base_events.py:1915(_run_once)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1228(resolve)\n",
|
|
" 2316 0.000 0.000 0.000 0.000 {method 'keys' of 'dict' objects}\n",
|
|
" 682 0.000 0.000 0.001 0.000 ascii.py:25(decode)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'read' of '_io.BufferedReader' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:60(isabs)\n",
|
|
" 4 0.000 0.000 0.000 0.000 attrsettr.py:66(_get_attr_opt)\n",
|
|
" 3/1 0.000 0.000 0.480 0.480 {built-in method builtins.exec}\n",
|
|
" 1158 0.000 0.000 0.000 0.000 {method 'values' of 'dict' objects}\n",
|
|
"1232/1228 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.getcwd}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'execute' of 'sqlite3.Connection' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
|
|
" 581 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.RLock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 socket.py:623(send)\n",
|
|
" 1 0.000 0.000 0.004 0.004 citation_network_slow.py:83(get_percentiles)\n",
|
|
" 2/1 0.000 0.000 0.000 0.000 interactiveshell.py:2878(safe_execfile)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method '__exit__' of '_io._IOBase' objects}\n",
|
|
" 9 0.000 0.000 0.000 0.000 {built-in method sys.intern}\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:662(write)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3631(set)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:3133(_bind)\n",
|
|
" 24 0.000 0.000 0.000 0.000 enum.py:1538(_get_value)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'run' of '_contextvars.Context' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 socket.py:771(recv_multipart)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method '__exit__' of 'sqlite3.Connection' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 attrsettr.py:43(__getattr__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:387(_parse_path)\n",
|
|
" 2 0.000 0.000 0.000 0.000 interactiveshell.py:3043(write)\n",
|
|
" 8 0.000 0.000 0.000 0.000 {built-in method builtins.next}\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:1024(writeout_cache)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.lstat}\n",
|
|
" 2 0.000 0.000 0.000 0.000 threading.py:299(__enter__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:573(_handle_events)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1527(_notify_observers)\n",
|
|
" 6 0.000 0.000 0.000 0.000 pathlib.py:437(__str__)\n",
|
|
" 9 0.000 0.000 0.000 0.000 traitlets.py:676(__get__)\n",
|
|
" 11 0.000 0.000 0.000 0.000 citation_network_slow.py:98(value_at_rank)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:1157(__init__)\n",
|
|
" 6 0.000 0.000 0.000 0.000 enum.py:1556(__and__)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:358(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _heapq.heappop}\n",
|
|
" 14 0.000 0.000 0.000 0.000 enum.py:720(__call__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:813(_call_soon)\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:407(_load_parts)\n",
|
|
" 9 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}\n",
|
|
" 4 0.000 0.000 0.000 0.000 events.py:86(_run)\n",
|
|
" 6 0.000 0.000 0.000 0.000 typing.py:392(inner)\n",
|
|
" 11 0.000 0.000 0.000 0.000 {method 'format' of 'str' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:71(join)\n",
|
|
" 9 0.000 0.000 0.000 0.000 traitlets.py:629(get)\n",
|
|
" 4 0.000 0.000 0.000 0.000 pathlib.py:551(drive)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3474(validate)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:1164(__new__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 decorator.py:200(fix)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:429(_format_parsed_parts)\n",
|
|
" 7/3 0.000 0.000 0.000 0.000 {method 'acquire' of '_thread.lock' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 base_events.py:766(call_at)\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:128(_event_pipe_gc)\n",
|
|
" 2 0.000 0.000 0.000 0.000 tasks.py:653(sleep)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:718(_validate)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method _heapq.heappush}\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:155(cancel)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:676(_update_handler)\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:119(_run_event_pipe_gc)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:689(set)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:423(realpath)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:727(_cross_validate)\n",
|
|
" 3 0.000 0.000 0.000 0.000 events.py:36(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.stat}\n",
|
|
" 1 0.000 0.000 0.000 0.000 decorator.py:232(fun)\n",
|
|
" 9 0.000 0.000 0.000 0.000 base_events.py:733(time)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:614(_handle_recv)\n",
|
|
" 2/1 0.000 0.000 0.000 0.000 <string>:1(<module>)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:3272(bind)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:11(__enter__)\n",
|
|
" 5 0.000 0.000 0.000 0.000 pathlib.py:447(__fspath__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:92(only_when_enabled)\n",
|
|
" 4 0.000 0.000 0.000 0.000 threading.py:1222(is_alive)\n",
|
|
" 8 0.000 0.000 0.000 0.000 {built-in method builtins.max}\n",
|
|
" 1 0.000 0.000 0.000 0.000 citation_network_slow.py:110(make_percentiles_table)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:432(_joinrealpath)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:653(_rebuild_io_state)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:708(__set__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 py3compat.py:52(execfile)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:2949(apply_defaults)\n",
|
|
" 4 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1390(_handle_fromlist)\n",
|
|
" 14 0.000 0.000 0.000 0.000 enum.py:1123(__new__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3624(validate_elements)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:408(abspath)\n",
|
|
" 4 0.000 0.000 0.000 0.000 typing.py:1285(__hash__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:260(schedule)\n",
|
|
" 2 0.000 0.000 0.000 0.000 base_events.py:742(call_later)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.print}\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:380(with_segments)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1512(_notify_trait)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1523(notify_change)\n",
|
|
" 1 0.000 0.000 0.000 0.000 contextlib.py:104(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:311(_acquire_restore)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:2304(validate)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1398(expanduser)\n",
|
|
" 1 0.000 0.000 0.000 0.000 contextlib.py:141(__exit__)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
|
|
" 2 0.000 0.000 0.000 0.000 queue.py:97(empty)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:2896(args)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:138(splitroot)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:158(_handle_event)\n",
|
|
" 12/11 0.000 0.000 0.000 0.000 {built-in method posix.fspath}\n",
|
|
" 2 0.000 0.000 0.000 0.000 typing.py:1492(__subclasscheck__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 contextlib.py:299(helper)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:731(parent)\n",
|
|
" 30 0.000 0.000 0.000 0.000 typing.py:2183(cast)\n",
|
|
" 9 0.000 0.000 0.000 0.000 {built-in method time.monotonic}\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:1016(_writeout_output_cache)\n",
|
|
" 1 0.000 0.000 0.000 0.000 zmqstream.py:684(<lambda>)\n",
|
|
" 1 0.000 0.000 0.000 0.000 asyncio.py:216(call_at)\n",
|
|
" 2 0.000 0.000 0.000 0.000 events.py:111(__init__)\n",
|
|
" 4 0.000 0.000 0.000 0.000 selector_events.py:750(_process_events)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1005(open)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:546(_run_callback)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 ioloop.py:604(call_later)\n",
|
|
" 1 0.000 0.000 0.000 0.000 futures.py:313(_set_result_unless_cancelled)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method _abc._abc_subclasscheck}\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:1008(_writeout_input_cache)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:18(__exit__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:557(_is_master_process)\n",
|
|
" 2 0.000 0.000 0.000 0.000 enum.py:1545(__or__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 typing.py:1221(__instancecheck__)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'set_result' of '_asyncio.Future' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 threading.py:302(__exit__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 contextlib.py:132(__enter__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:584(_schedule_flush)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen abc>:121(__subclasscheck__)\n",
|
|
" 7 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:308(_release_save)\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:627(clear)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x101e64a30}\n",
|
|
" 4 0.000 0.000 0.000 0.000 <frozen posixpath>:41(_get_sep)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 ioloop.py:750(_run_callback)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:2919(kwargs)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:512(parent_header)\n",
|
|
" 4 0.000 0.000 0.000 0.000 threading.py:1155(_wait_for_tstate_lock)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'values' of 'mappingproxy' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:594(_schedule_in_thread)\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:446(create_future)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:532(sending)\n",
|
|
" 2 0.000 0.000 0.000 0.000 ioloop.py:549(time)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:420(_from_parsed_parts)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {method 'append' of 'collections.deque' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _thread.allocate_lock}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix._path_normpath}\n",
|
|
" 1 0.000 0.000 0.000 0.000 builtin_trap.py:53(__exit__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3486(validate_elements)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:835(stat)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {method 'popleft' of 'collections.deque' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:139(_event_pipe)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {built-in method builtins.min}\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen codecs>:260(__init__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method _contextvars.copy_context}\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method 'items' of 'mappingproxy' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:131(splitdrive)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:784(call_soon)\n",
|
|
" 1 0.000 0.000 0.000 0.000 builtin_trap.py:46(__enter__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 asyncio.py:206(_handle_events)\n",
|
|
" 10 0.000 0.000 0.000 0.000 inspect.py:2808(kind)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.getppid}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'write' of '_io.StringIO' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 history.py:1065(hold)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method '__enter__' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:1900(_add_callback)\n",
|
|
" 2 0.000 0.000 0.000 0.000 queue.py:209(_qsize)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:8(__init__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.iter}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'partition' of 'str' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 zmqstream.py:528(receiving)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {built-in method builtins.hash}\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:72(cancel)\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:314(_is_owned)\n",
|
|
" 4 0.000 0.000 0.000 0.000 inspect.py:2796(name)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method time.time}\n",
|
|
" 5 0.000 0.000 0.000 0.000 pathlib.py:569(_tail)\n",
|
|
" 1 0.000 0.000 0.000 0.000 selectors.py:275(_key_from_fd)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'remove' of 'list' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method posix.getpid}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'insert' of 'list' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'get' of '_contextvars.ContextVar' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.any}\n",
|
|
" 4 0.000 0.000 0.000 0.000 pathlib.py:560(root)\n",
|
|
" 4 0.000 0.000 0.000 0.000 inspect.py:3089(parameters)\n",
|
|
" 3 0.000 0.000 0.000 0.000 base_events.py:538(_check_closed)\n",
|
|
" 1 0.000 0.000 0.000 0.000 inspect.py:2888(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _stat.S_ISLNK}\n",
|
|
" 4 0.000 0.000 0.000 0.000 threading.py:601(is_set)\n",
|
|
" 5 0.000 0.000 0.000 0.000 base_events.py:2010(get_debug)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'endswith' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'release' of '_thread.lock' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 displaypub.py:172(is_publishing)\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:127(__lt__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 tz.py:74(utcoffset)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <string>:2(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'cancelled' of '_asyncio.Future' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 displayhook.py:118(is_active)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _asyncio.get_running_loop}\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:1910(_timer_handle_cancelled)"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"%run -p citation_network_slow.py"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3c67c5fc-bacc-477c-b193-dae66aeb9c1b",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Note** Changed the data structure from `{str: list}` to `{str: set}`"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"id": "d0a40bf7-9172-478a-a75d-4a0dc34a4c7b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0.0% 0\n",
|
|
" 10.0% 0\n",
|
|
" 20.0% 1\n",
|
|
" 30.0% 1\n",
|
|
" 40.0% 3\n",
|
|
" 50.0% 4\n",
|
|
" 60.0% 6\n",
|
|
" 70.0% 9\n",
|
|
" 80.0% 15\n",
|
|
" 90.0% 29\n",
|
|
"100.0% 2414\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
" 1100898 function calls (1100891 primitive calls) in 0.373 seconds\n",
|
|
"\n",
|
|
" Ordered by: internal time\n",
|
|
"\n",
|
|
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
|
|
" 1 0.154 0.154 0.207 0.207 citation_network_fix.py:37(load_citations)\n",
|
|
" 1 0.110 0.110 0.134 0.134 citation_network_fix.py:53(build_index)\n",
|
|
" 352809 0.031 0.000 0.031 0.000 {method 'split' of 'str' objects}\n",
|
|
" 352807 0.023 0.000 0.023 0.000 {method 'add' of 'set' objects}\n",
|
|
" 352825 0.018 0.000 0.018 0.000 {method 'append' of 'list' objects}\n",
|
|
" 1 0.015 0.015 0.365 0.365 citation_network_fix.py:1(<module>)\n",
|
|
" 1 0.005 0.005 0.005 0.005 {built-in method builtins.sorted}\n",
|
|
" 1 0.003 0.003 0.004 0.004 citation_network_fix.py:74(citation_counts)\n",
|
|
" 1 0.003 0.003 0.370 0.370 base_events.py:1915(_run_once)\n",
|
|
" 1160 0.002 0.000 0.004 0.000 ipkernel.py:797(_clean_thread_parent_frames)\n",
|
|
" 1 0.001 0.001 0.001 0.001 {built-in method builtins.compile}\n",
|
|
" 682 0.001 0.000 0.001 0.000 {built-in method _codecs.ascii_decode}\n",
|
|
" 2/1 0.001 0.000 0.371 0.371 {built-in method builtins.exec}\n",
|
|
" 27797 0.001 0.000 0.001 0.000 {built-in method builtins.len}\n",
|
|
" 5800 0.001 0.000 0.001 0.000 threading.py:1198(ident)\n",
|
|
" 580 0.001 0.000 0.001 0.000 threading.py:1535(enumerate)\n",
|
|
" 1 0.000 0.000 0.351 0.351 citation_network_fix.py:118(main)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {built-in method _io.open}\n",
|
|
" 9 0.000 0.000 0.000 0.000 {built-in method sys.intern}\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:420(_from_parsed_parts)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.getcwd}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'read' of '_io.BufferedReader' objects}\n",
|
|
" 2320 0.000 0.000 0.000 0.000 {method 'keys' of 'dict' objects}\n",
|
|
" 682 0.000 0.000 0.001 0.000 ascii.py:25(decode)\n",
|
|
" 2 0.000 0.000 0.000 0.000 enum.py:1545(__or__)\n",
|
|
" 4 0.000 0.000 0.000 0.000 attrsettr.py:66(_get_attr_opt)\n",
|
|
" 1160 0.000 0.000 0.000 0.000 {method 'values' of 'dict' objects}\n",
|
|
" 2 0.000 0.000 0.001 0.000 zmqstream.py:573(_handle_events)\n",
|
|
" 6 0.000 0.000 0.000 0.000 enum.py:1556(__and__)\n",
|
|
"1234/1230 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:387(_parse_path)\n",
|
|
" 582 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.RLock' objects}\n",
|
|
" 1 0.000 0.000 0.005 0.005 citation_network_fix.py:83(get_percentiles)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 socket.py:623(send)\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:380(with_segments)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:1164(__new__)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method '__exit__' of '_io._IOBase' objects}\n",
|
|
" 6 0.000 0.000 0.000 0.000 pathlib.py:437(__str__)\n",
|
|
" 5 0.000 0.000 0.000 0.000 pathlib.py:447(__fspath__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:408(abspath)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3631(set)\n",
|
|
" 4 0.000 0.000 0.000 0.000 pathlib.py:551(drive)\n",
|
|
" 2 0.000 0.000 0.000 0.000 pathlib.py:407(_load_parts)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method '__exit__' of 'sqlite3.Connection' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:662(write)\n",
|
|
" 1 0.000 0.000 0.367 0.367 {method 'control' of 'select.kqueue' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 attrsettr.py:43(__getattr__)\n",
|
|
" 6 0.000 0.000 0.000 0.000 typing.py:392(inner)\n",
|
|
" 2 0.000 0.000 0.000 0.000 socket.py:771(recv_multipart)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:429(_format_parsed_parts)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:71(join)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:653(_rebuild_io_state)\n",
|
|
" 2 0.000 0.000 0.000 0.000 interactiveshell.py:3043(write)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:358(__init__)\n",
|
|
" 3 0.000 0.000 0.000 0.000 pathlib.py:1157(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:11(__enter__)\n",
|
|
" 14 0.000 0.000 0.000 0.000 enum.py:720(__call__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:718(_validate)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.stat}\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:308(_release_save)\n",
|
|
" 1 0.000 0.000 0.367 0.367 selectors.py:558(select)\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:766(call_at)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1228(resolve)\n",
|
|
" 24 0.000 0.000 0.000 0.000 enum.py:1538(_get_value)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix.lstat}\n",
|
|
" 11 0.000 0.000 0.000 0.000 citation_network_fix.py:98(value_at_rank)\n",
|
|
" 1 0.000 0.000 0.000 0.000 citation_network_fix.py:110(make_percentiles_table)\n",
|
|
" 5 0.000 0.000 0.000 0.000 base_events.py:733(time)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1527(_notify_observers)\n",
|
|
" 11 0.000 0.000 0.000 0.000 {method 'format' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 interactiveshell.py:2878(safe_execfile)\n",
|
|
" 2 0.000 0.000 0.000 0.000 ioloop.py:549(time)\n",
|
|
" 9 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:111(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.print}\n",
|
|
" 1 0.000 0.000 0.000 0.000 ioloop.py:604(call_later)\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:36(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1398(expanduser)\n",
|
|
" 2 0.000 0.000 0.000 0.000 queue.py:97(empty)\n",
|
|
" 6 0.000 0.000 0.000 0.000 traitlets.py:676(__get__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:432(_joinrealpath)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3474(validate)\n",
|
|
" 2 0.000 0.000 0.001 0.000 events.py:86(_run)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen codecs>:260(__init__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:614(_handle_recv)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:138(splitroot)\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:1222(is_alive)\n",
|
|
" 14 0.000 0.000 0.000 0.000 enum.py:1123(__new__)\n",
|
|
" 4 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1390(_handle_fromlist)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.next}\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:689(set)\n",
|
|
" 4 0.000 0.000 0.000 0.000 typing.py:1285(__hash__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:260(schedule)\n",
|
|
" 1 0.000 0.000 0.000 0.000 asyncio.py:216(call_at)\n",
|
|
" 12/11 0.000 0.000 0.000 0.000 {built-in method posix.fspath}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}\n",
|
|
" 2 0.000 0.000 0.001 0.000 {method 'run' of '_contextvars.Context' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 py3compat.py:52(execfile)\n",
|
|
" 2 0.000 0.000 0.000 0.000 selector_events.py:750(_process_events)\n",
|
|
" 1 0.000 0.000 0.001 0.001 zmqstream.py:684(<lambda>)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:742(call_later)\n",
|
|
" 6 0.000 0.000 0.000 0.000 traitlets.py:629(get)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
|
|
" 3 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x101e64a30}\n",
|
|
" 1 0.000 0.000 0.000 0.000 contextlib.py:141(__exit__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3624(validate_elements)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen posixpath>:60(isabs)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:546(_run_callback)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:708(__set__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:727(_cross_validate)\n",
|
|
" 2 0.000 0.000 0.000 0.000 typing.py:1492(__subclasscheck__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:423(realpath)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1512(_notify_trait)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:158(_handle_event)\n",
|
|
" 1 0.000 0.000 0.000 0.000 traitlets.py:1523(notify_change)\n",
|
|
" 1 0.000 0.000 0.000 0.000 <string>:1(<module>)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:676(_update_handler)\n",
|
|
" 4 0.000 0.000 0.000 0.000 <frozen posixpath>:41(_get_sep)\n",
|
|
" 2 0.000 0.000 0.000 0.000 typing.py:1221(__instancecheck__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method _abc._abc_subclasscheck}\n",
|
|
" 1 0.000 0.000 0.001 0.001 ioloop.py:750(_run_callback)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {built-in method builtins.max}\n",
|
|
" 3/2 0.000 0.000 0.000 0.000 {method 'acquire' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:139(_event_pipe)\n",
|
|
" 2 0.000 0.000 0.000 0.000 <frozen abc>:121(__subclasscheck__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:512(parent_header)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:1005(open)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method posix._path_normpath}\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:731(parent)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:584(_schedule_flush)\n",
|
|
" 1 0.000 0.000 0.000 0.000 builtin_trap.py:53(__exit__)\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:2304(validate)\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:1016(_writeout_output_cache)\n",
|
|
" 2 0.000 0.000 0.000 0.000 iostream.py:557(_is_master_process)\n",
|
|
" 2 0.000 0.000 0.000 0.000 zmqstream.py:532(sending)\n",
|
|
" 1 0.000 0.000 0.000 0.000 pathlib.py:835(stat)\n",
|
|
" 24 0.000 0.000 0.000 0.000 typing.py:2183(cast)\n",
|
|
" 5 0.000 0.000 0.000 0.000 {built-in method time.monotonic}\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method 'append' of 'collections.deque' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:299(__enter__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:18(__exit__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 iostream.py:594(_schedule_in_thread)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _contextvars.copy_context}\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 queue.py:209(_qsize)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _heapq.heappush}\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:601(is_set)\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:314(_is_owned)\n",
|
|
" 1 0.000 0.000 0.000 0.000 builtin_trap.py:46(__enter__)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 traitlets.py:3486(validate_elements)\n",
|
|
" 4 0.000 0.000 0.000 0.000 {method '__exit__' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 <frozen posixpath>:131(splitdrive)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _thread.allocate_lock}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'partition' of 'str' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.min}\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method 'popleft' of 'collections.deque' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:1900(_add_callback)\n",
|
|
" 1 0.000 0.000 0.000 0.000 asyncio.py:206(_handle_events)\n",
|
|
" 5 0.000 0.000 0.000 0.000 pathlib.py:569(_tail)\n",
|
|
" 3 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 pathlib.py:560(root)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'write' of '_io.StringIO' objects}\n",
|
|
" 4 0.000 0.000 0.000 0.000 zmqstream.py:528(receiving)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'remove' of 'list' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.any}\n",
|
|
" 4 0.000 0.000 0.000 0.000 {built-in method builtins.hash}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'get' of '_contextvars.ContextVar' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'endswith' of 'str' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method posix.getpid}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method '__enter__' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 tz.py:74(utcoffset)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'insert' of 'list' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 threading.py:1155(_wait_for_tstate_lock)\n",
|
|
" 2 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}\n",
|
|
" 2 0.000 0.000 0.000 0.000 {built-in method time.time}\n",
|
|
" 1 0.000 0.000 0.000 0.000 {built-in method _stat.S_ISLNK}\n",
|
|
" 1 0.000 0.000 0.000 0.000 events.py:127(__lt__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 {method 'release' of '_thread.lock' objects}\n",
|
|
" 1 0.000 0.000 0.000 0.000 <string>:2(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 syspathcontext.py:8(__init__)\n",
|
|
" 1 0.000 0.000 0.000 0.000 history.py:1065(hold)\n",
|
|
" 1 0.000 0.000 0.000 0.000 selectors.py:275(_key_from_fd)\n",
|
|
" 2 0.000 0.000 0.000 0.000 displayhook.py:118(is_active)\n",
|
|
" 2 0.000 0.000 0.000 0.000 displaypub.py:172(is_publishing)\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:538(_check_closed)\n",
|
|
" 1 0.000 0.000 0.000 0.000 base_events.py:2010(get_debug)"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"%run -p citation_network_fix.py"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"id": "d9bf9a89-462e-4708-9e71-153f4ca29ea6",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0.22916666666666666"
|
|
]
|
|
},
|
|
"execution_count": 35,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"(.48 - .37) / .48"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "294bb35e-c488-43e2-a758-a14416b41c99",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Debugging"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"id": "a71c6680-8579-4974-a607-d62d1038fbb3",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network'"
|
|
]
|
|
},
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"pwd"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"id": "6fef30a7-8327-40e7-a323-99ae4a5541b4",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"cd .."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"id": "3249b929-6df3-41f4-bb45-23fc3b3e70bb",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"cd ../pdb/"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"id": "4d4d55fe-b583-4f50-89b7-a9be3bed73db",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"dir.dat file_sum.py middle.py README.rst\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"ls"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"id": "0eb1b3c7-331a-421e-9a99-c732229b41a1",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Automatic pdb calling has been turned ON\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%pdb"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 43,
|
|
"id": "d640dd19-a884-4493-8290-968554254800",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import middle"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 44,
|
|
"id": "f7a2ad78-4cca-4d56-956d-10d396cdc5d9",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "IndexError",
|
|
"evalue": "list index out of range",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
|
"\u001b[31mIndexError\u001b[39m Traceback (most recent call last)",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[44]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mmiddle\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
|
|
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/Diller_Digital_SWNG/demo/pdb/middle.py:35\u001b[39m, in \u001b[36mrun\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 33\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[32m1\u001b[39m, \u001b[32m11\u001b[39m):\n\u001b[32m 34\u001b[39m list_of_length_i = make_list(i)\n\u001b[32m---> \u001b[39m\u001b[32m35\u001b[39m middle = \u001b[43mget_middle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlist_of_length_i\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 36\u001b[39m template = \u001b[33m\"\u001b[39m\u001b[33mThe middle item(s) in \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[33mis/are \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 37\u001b[39m \u001b[38;5;28mprint\u001b[39m(template.format(list_of_length_i, middle))\n",
|
|
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/Diller_Digital_SWNG/demo/pdb/middle.py:10\u001b[39m, in \u001b[36mget_middle\u001b[39m\u001b[34m(item_list)\u001b[39m\n\u001b[32m 7\u001b[39m half = num_items * \u001b[32m2\u001b[39m\n\u001b[32m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n\u001b[32m---> \u001b[39m\u001b[32m10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mitem_list\u001b[49m\u001b[43m[\u001b[49m\u001b[43mhalf\u001b[49m\u001b[43m]\u001b[49m\n\u001b[32m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\u001b[31mIndexError\u001b[39m: list index out of range"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"> \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m10\u001b[39m)\u001b[36mget_middle\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m 8\u001b[39m \n",
|
|
"\u001b[32m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[32m 11\u001b[39m \n",
|
|
"\u001b[32m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> half\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> len(item_list)\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> ?\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Object `` not found.\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> h\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"Documented commands (type help <topic>):\n",
|
|
"========================================\n",
|
|
"EOF cont help p return undisplay \n",
|
|
"a context ignore pdef retval unignore_module\n",
|
|
"alias continue ignore_module pdoc run unt \n",
|
|
"args d interact pfile rv until \n",
|
|
"b debug j pinfo s up \n",
|
|
"break disable jump pinfo2 skip_hidden w \n",
|
|
"bt display l pp skip_predicates whatis \n",
|
|
"c down list psource source where \n",
|
|
"cl enable ll q step \n",
|
|
"clear exceptions longlist quit tbreak \n",
|
|
"commands exit n r u \n",
|
|
"condition h next restart unalias \n",
|
|
"\n",
|
|
"Miscellaneous help topics:\n",
|
|
"==========================\n",
|
|
"exec pdb\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> l\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[92m 5\u001b[39m \"\"\"\n",
|
|
"\u001b[92m 6\u001b[39m num_items = len(item_list)\n",
|
|
"\u001b[92m 7\u001b[39m half = num_items * \u001b[32m2\u001b[39m\n",
|
|
"\u001b[92m 8\u001b[39m \n",
|
|
"\u001b[92m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[92m 11\u001b[39m \n",
|
|
"\u001b[92m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\u001b[92m 13\u001b[39m \n",
|
|
"\u001b[92m 14\u001b[39m \n",
|
|
"\u001b[92m 15\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m make_list(size=\u001b[32m0\u001b[39m):\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> half = num_items / 2\n",
|
|
"ipdb> item_list[half]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"*** TypeError: list indices must be integers or slices, not float\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> half = num_items // 2\n",
|
|
"ipdb> item_list[half]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"'0'\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> args\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"item_list = ['0']\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> where\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[31m [... skipping 1 hidden frame(s)]\u001b[39m\n",
|
|
" \u001b[32m/var/folders/4p/zx544knx2qzgc26tg4g508gm0000gn/T/ipykernel_16438/4003336241.py\u001b[39m(\u001b[92m1\u001b[39m)\u001b[36m<module>\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m----> 1\u001b[39m middle.run()\n",
|
|
" \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m35\u001b[39m)\u001b[36mrun\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[92m 33\u001b[39m \u001b[31m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;28;01min\u001b[39;00m range(\u001b[32m1\u001b[39m, \u001b[32m11\u001b[39m):\u001b[39m\n",
|
|
"\u001b[92m 34\u001b[39m \u001b[31m list_of_length_i = make_list(i)\u001b[39m\n",
|
|
"\u001b[32m---> 35\u001b[39m middle = get_middle(list_of_length_i)\n",
|
|
"\u001b[92m 36\u001b[39m \u001b[31m template = \u001b[33m\"The middle item(s) in {}\\n\\tis/are {}\\n\"\u001b[39m\u001b[39m\n",
|
|
"\u001b[92m 37\u001b[39m \u001b[31m print(template.format(list_of_length_i, middle))\u001b[39m\n",
|
|
"> \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m10\u001b[39m)\u001b[36mget_middle\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m 8\u001b[39m \n",
|
|
"\u001b[32m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[32m 11\u001b[39m \n",
|
|
"\u001b[32m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> up\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"> \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m35\u001b[39m)\u001b[36mrun\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m 33\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;28;01min\u001b[39;00m range(\u001b[32m1\u001b[39m, \u001b[32m11\u001b[39m):\n",
|
|
"\u001b[32m 34\u001b[39m list_of_length_i = make_list(i)\n",
|
|
"\u001b[32m---> 35\u001b[39m middle = get_middle(list_of_length_i)\n",
|
|
"\u001b[32m 36\u001b[39m template = \u001b[33m\"The middle item(s) in {}\\n\\tis/are {}\\n\"\u001b[39m\n",
|
|
"\u001b[32m 37\u001b[39m print(template.format(list_of_length_i, middle))\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> list_of_length_i\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['0']\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> where\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[31m [... skipping 1 hidden frame(s)]\u001b[39m\n",
|
|
" \u001b[32m/var/folders/4p/zx544knx2qzgc26tg4g508gm0000gn/T/ipykernel_16438/4003336241.py\u001b[39m(\u001b[92m1\u001b[39m)\u001b[36m<module>\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m----> 1\u001b[39m middle.run()\n",
|
|
"> \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m35\u001b[39m)\u001b[36mrun\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m 33\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;28;01min\u001b[39;00m range(\u001b[32m1\u001b[39m, \u001b[32m11\u001b[39m):\n",
|
|
"\u001b[32m 34\u001b[39m list_of_length_i = make_list(i)\n",
|
|
"\u001b[32m---> 35\u001b[39m middle = get_middle(list_of_length_i)\n",
|
|
"\u001b[32m 36\u001b[39m template = \u001b[33m\"The middle item(s) in {}\\n\\tis/are {}\\n\"\u001b[39m\n",
|
|
"\u001b[32m 37\u001b[39m print(template.format(list_of_length_i, middle))\n",
|
|
" \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m10\u001b[39m)\u001b[36mget_middle\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[92m 8\u001b[39m \n",
|
|
"\u001b[92m 9\u001b[39m \u001b[31m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\u001b[39m\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[92m 11\u001b[39m \n",
|
|
"\u001b[92m 12\u001b[39m \u001b[31m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\u001b[39m\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> down\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"> \u001b[32m/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py\u001b[39m(\u001b[92m10\u001b[39m)\u001b[36mget_middle\u001b[39m\u001b[34m()\u001b[39m\n",
|
|
"\u001b[32m 8\u001b[39m \n",
|
|
"\u001b[32m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[32m 11\u001b[39m \n",
|
|
"\u001b[32m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> help\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"Documented commands (type help <topic>):\n",
|
|
"========================================\n",
|
|
"EOF cont help p return undisplay \n",
|
|
"a context ignore pdef retval unignore_module\n",
|
|
"alias continue ignore_module pdoc run unt \n",
|
|
"args d interact pfile rv until \n",
|
|
"b debug j pinfo s up \n",
|
|
"break disable jump pinfo2 skip_hidden w \n",
|
|
"bt display l pp skip_predicates whatis \n",
|
|
"c down list psource source where \n",
|
|
"cl enable ll q step \n",
|
|
"clear exceptions longlist quit tbreak \n",
|
|
"commands exit n r u \n",
|
|
"condition h next restart unalias \n",
|
|
"\n",
|
|
"Miscellaneous help topics:\n",
|
|
"==========================\n",
|
|
"exec pdb\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> list\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[92m 5\u001b[39m \"\"\"\n",
|
|
"\u001b[92m 6\u001b[39m num_items = len(item_list)\n",
|
|
"\u001b[92m 7\u001b[39m half = num_items * \u001b[32m2\u001b[39m\n",
|
|
"\u001b[92m 8\u001b[39m \n",
|
|
"\u001b[92m 9\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m num_items % \u001b[32m2\u001b[39m:\n",
|
|
"\u001b[32m---> 10\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[half]\n",
|
|
"\u001b[92m 11\u001b[39m \n",
|
|
"\u001b[92m 12\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m item_list[(half - \u001b[32m1\u001b[39m):(half + \u001b[32m1\u001b[39m)]\n",
|
|
"\u001b[92m 13\u001b[39m \n",
|
|
"\u001b[92m 14\u001b[39m \n",
|
|
"\u001b[92m 15\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m make_list(size=\u001b[32m0\u001b[39m):\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdin",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ipdb> next\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"middle.run()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"id": "62892f9d-9f93-4270-8031-5ae75e518788",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>"
|
|
]
|
|
},
|
|
"execution_count": 45,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from importlib import reload\n",
|
|
"reload(middle)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 46,
|
|
"id": "9b28f7a4-1c2c-4560-9aa9-685150466c85",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The middle item(s) in ['0']\n",
|
|
"\tis/are 0\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1']\n",
|
|
"\tis/are ['0', '1']\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2']\n",
|
|
"\tis/are 1\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3']\n",
|
|
"\tis/are ['1', '2']\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4']\n",
|
|
"\tis/are 2\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4', '5']\n",
|
|
"\tis/are ['2', '3']\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4', '5', '6']\n",
|
|
"\tis/are 3\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4', '5', '6', '7']\n",
|
|
"\tis/are ['3', '4']\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4', '5', '6', '7', '8']\n",
|
|
"\tis/are 4\n",
|
|
"\n",
|
|
"The middle item(s) in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n",
|
|
"\tis/are ['4', '5']\n",
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"middle.run()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 47,
|
|
"id": "a55db015-7338-4673-83c4-27a4620b8bbc",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'__name__': '__main__',\n",
|
|
" '__doc__': 'Module created for script run in IPython',\n",
|
|
" '__package__': None,\n",
|
|
" '__loader__': None,\n",
|
|
" '__spec__': None,\n",
|
|
" '__builtin__': <module 'builtins' (built-in)>,\n",
|
|
" '__builtins__': <module 'builtins' (built-in)>,\n",
|
|
" '_ih': ['',\n",
|
|
" \"get_ipython().run_line_magic('run', 'live_coding/lecture05.py')\",\n",
|
|
" \"get_ipython().run_line_magic('whos', '')\",\n",
|
|
" \"get_ipython().run_line_magic('pinfo2', 'test_logging')\",\n",
|
|
" 'test_logg()',\n",
|
|
" 'test_logging()',\n",
|
|
" 'import logging\\nlogging.basicConfig(level=logging.INFO)',\n",
|
|
" 'test_logging()',\n",
|
|
" 'import logging\\nlogging.basicConfig(level=logging.INFO, force=True)',\n",
|
|
" 'test_logging()',\n",
|
|
" 'logger = logging.getLogger()',\n",
|
|
" 'logger',\n",
|
|
" 'logger.setLevel(logging.ERROR)\\ntest_logging()',\n",
|
|
" 'logger.setLevel(logging.NOTSET)\\ntest_logging()',\n",
|
|
" 'logger.info(\"Hello my name is Inigo\")',\n",
|
|
" 'logger.handlers',\n",
|
|
" 'h = logger.handlers[0]\\nh',\n",
|
|
" 'h.setLevel(logging.ERROR)',\n",
|
|
" 'logger.info(\"Hello\")',\n",
|
|
" 'h.formatter',\n",
|
|
" 'f = h.formatter',\n",
|
|
" 'f.format',\n",
|
|
" 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)s\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" 'test_logging()',\n",
|
|
" 'logging.basicConfig(force=True)\\ntest_logging()',\n",
|
|
" '__name__',\n",
|
|
" 'logger = logging.getLogger(__name__)',\n",
|
|
" 'logger.warning(\"Hi\")',\n",
|
|
" 'import sys\\nh2 = logging.StreamHandler(sys.stdout)',\n",
|
|
" 'logger = logging.getLogger(__name__)\\nlogger.handlers.append(h2)',\n",
|
|
" 'logger.error(\"Hi\")',\n",
|
|
" \"get_ipython().run_line_magic('cd', 'demo/Software_Engineering/citation_network/')\",\n",
|
|
" \"get_ipython().run_line_magic('run', '-p citation_network_slow.py')\",\n",
|
|
" \"get_ipython().run_line_magic('run', '-p citation_network_fix.py')\",\n",
|
|
" '(.48 - .37) / .48',\n",
|
|
" \"get_ipython().run_line_magic('pwd', '')\",\n",
|
|
" \"get_ipython().run_line_magic('cd', '..')\",\n",
|
|
" \"get_ipython().run_line_magic('cd', '../pdb/')\",\n",
|
|
" \"get_ipython().run_line_magic('ls', '')\",\n",
|
|
" \"get_ipython().run_line_magic('debug', '')\",\n",
|
|
" \"get_ipython().run_line_magic('pdb', '')\",\n",
|
|
" \"get_ipython().run_line_magic('run', 'middle.py')\",\n",
|
|
" 'import middle',\n",
|
|
" 'middle.run()',\n",
|
|
" 'from importlib import reload\\nreload(middle)',\n",
|
|
" 'middle.run()',\n",
|
|
" 'locals()'],\n",
|
|
" '_oh': {11: <RootLogger root (NOTSET)>,\n",
|
|
" 15: [<StreamHandler stderr (NOTSET)>],\n",
|
|
" 16: <StreamHandler stderr (ERROR)>,\n",
|
|
" 19: <logging.Formatter at 0x107065640>,\n",
|
|
" 21: <bound method Formatter.format of <logging.Formatter object at 0x107065640>>,\n",
|
|
" 26: '__main__',\n",
|
|
" 35: 0.22916666666666666,\n",
|
|
" 36: '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network',\n",
|
|
" 45: <module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>},\n",
|
|
" '_dh': [PosixPath('/Users/timdiller/Documents/Diller_Digital_SWNG'),\n",
|
|
" PosixPath('/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network'),\n",
|
|
" PosixPath('/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering'),\n",
|
|
" PosixPath('/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb')],\n",
|
|
" 'In': ['',\n",
|
|
" \"get_ipython().run_line_magic('run', 'live_coding/lecture05.py')\",\n",
|
|
" \"get_ipython().run_line_magic('whos', '')\",\n",
|
|
" \"get_ipython().run_line_magic('pinfo2', 'test_logging')\",\n",
|
|
" 'test_logg()',\n",
|
|
" 'test_logging()',\n",
|
|
" 'import logging\\nlogging.basicConfig(level=logging.INFO)',\n",
|
|
" 'test_logging()',\n",
|
|
" 'import logging\\nlogging.basicConfig(level=logging.INFO, force=True)',\n",
|
|
" 'test_logging()',\n",
|
|
" 'logger = logging.getLogger()',\n",
|
|
" 'logger',\n",
|
|
" 'logger.setLevel(logging.ERROR)\\ntest_logging()',\n",
|
|
" 'logger.setLevel(logging.NOTSET)\\ntest_logging()',\n",
|
|
" 'logger.info(\"Hello my name is Inigo\")',\n",
|
|
" 'logger.handlers',\n",
|
|
" 'h = logger.handlers[0]\\nh',\n",
|
|
" 'h.setLevel(logging.ERROR)',\n",
|
|
" 'logger.info(\"Hello\")',\n",
|
|
" 'h.formatter',\n",
|
|
" 'f = h.formatter',\n",
|
|
" 'f.format',\n",
|
|
" 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)s\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" 'test_logging()',\n",
|
|
" 'logging.basicConfig(force=True)\\ntest_logging()',\n",
|
|
" '__name__',\n",
|
|
" 'logger = logging.getLogger(__name__)',\n",
|
|
" 'logger.warning(\"Hi\")',\n",
|
|
" 'import sys\\nh2 = logging.StreamHandler(sys.stdout)',\n",
|
|
" 'logger = logging.getLogger(__name__)\\nlogger.handlers.append(h2)',\n",
|
|
" 'logger.error(\"Hi\")',\n",
|
|
" \"get_ipython().run_line_magic('cd', 'demo/Software_Engineering/citation_network/')\",\n",
|
|
" \"get_ipython().run_line_magic('run', '-p citation_network_slow.py')\",\n",
|
|
" \"get_ipython().run_line_magic('run', '-p citation_network_fix.py')\",\n",
|
|
" '(.48 - .37) / .48',\n",
|
|
" \"get_ipython().run_line_magic('pwd', '')\",\n",
|
|
" \"get_ipython().run_line_magic('cd', '..')\",\n",
|
|
" \"get_ipython().run_line_magic('cd', '../pdb/')\",\n",
|
|
" \"get_ipython().run_line_magic('ls', '')\",\n",
|
|
" \"get_ipython().run_line_magic('debug', '')\",\n",
|
|
" \"get_ipython().run_line_magic('pdb', '')\",\n",
|
|
" \"get_ipython().run_line_magic('run', 'middle.py')\",\n",
|
|
" 'import middle',\n",
|
|
" 'middle.run()',\n",
|
|
" 'from importlib import reload\\nreload(middle)',\n",
|
|
" 'middle.run()',\n",
|
|
" 'locals()'],\n",
|
|
" 'Out': {11: <RootLogger root (NOTSET)>,\n",
|
|
" 15: [<StreamHandler stderr (NOTSET)>],\n",
|
|
" 16: <StreamHandler stderr (ERROR)>,\n",
|
|
" 19: <logging.Formatter at 0x107065640>,\n",
|
|
" 21: <bound method Formatter.format of <logging.Formatter object at 0x107065640>>,\n",
|
|
" 26: '__main__',\n",
|
|
" 35: 0.22916666666666666,\n",
|
|
" 36: '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network',\n",
|
|
" 45: <module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>},\n",
|
|
" 'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x1069fe150>>,\n",
|
|
" 'exit': <IPython.core.autocall.ZMQExitAutocall at 0x1070343e0>,\n",
|
|
" 'quit': <IPython.core.autocall.ZMQExitAutocall at 0x1070343e0>,\n",
|
|
" 'open': <function _io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)>,\n",
|
|
" '_': <module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>,\n",
|
|
" '__': '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network',\n",
|
|
" '___': 0.22916666666666666,\n",
|
|
" '__session__': '/Users/timdiller/Documents/Diller_Digital_SWNG/Untitled.ipynb',\n",
|
|
" '_i': 'middle.run()',\n",
|
|
" '_ii': 'from importlib import reload\\nreload(middle)',\n",
|
|
" '_iii': 'middle.run()',\n",
|
|
" '_i1': '%run live_coding/lecture05.py',\n",
|
|
" '__nonzero__': <function IPython.core.interactiveshell.InteractiveShell.new_main_mod.<locals>.<lambda>()>,\n",
|
|
" 'logging': <module 'logging' from '/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py'>,\n",
|
|
" 'test_logging': <function __main__.test_logging()>,\n",
|
|
" 'div': <function __main__.div(x, y)>,\n",
|
|
" '_i2': 'whos',\n",
|
|
" '_i3': 'test_logging??',\n",
|
|
" '_i4': 'test_logg()',\n",
|
|
" '_i5': 'test_logging()',\n",
|
|
" '_i6': 'import logging\\nlogging.basicConfig(level=logging.INFO)',\n",
|
|
" '_i7': 'test_logging()',\n",
|
|
" '_i8': 'import logging\\nlogging.basicConfig(level=logging.INFO, force=True)',\n",
|
|
" '_i9': 'test_logging()',\n",
|
|
" '_i10': 'logger = logging.getLogger()',\n",
|
|
" 'logger': <Logger __main__ (NOTSET)>,\n",
|
|
" '_i11': 'logger',\n",
|
|
" '_11': <RootLogger root (NOTSET)>,\n",
|
|
" '_i12': 'logger.setLevel(logging.ERROR)\\ntest_logging()',\n",
|
|
" '_i13': 'logger.setLevel(logging.NOTSET)\\ntest_logging()',\n",
|
|
" '_i14': 'logger.info(\"Hello my name is Inigo\")',\n",
|
|
" '_i15': 'logger.handlers',\n",
|
|
" '_15': [<StreamHandler stderr (NOTSET)>],\n",
|
|
" '_i16': 'h = logger.handlers[0]\\nh',\n",
|
|
" 'h': <StreamHandler stderr (ERROR)>,\n",
|
|
" '_16': <StreamHandler stderr (ERROR)>,\n",
|
|
" '_i17': 'h.setLevel(logging.ERROR)',\n",
|
|
" '_i18': 'logger.info(\"Hello\")',\n",
|
|
" '_i19': 'h.formatter',\n",
|
|
" '_19': <logging.Formatter at 0x107065640>,\n",
|
|
" '_i20': 'f = h.formatter',\n",
|
|
" 'f': <logging.Formatter at 0x107065640>,\n",
|
|
" '_i21': 'f.format',\n",
|
|
" '_21': <bound method Formatter.format of <logging.Formatter object at 0x107065640>>,\n",
|
|
" '_i22': 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" 'f2': <logging.Formatter at 0x119179760>,\n",
|
|
" '_i23': 'f2 = logging.Formatter(\\'%(asctime)s:%(funcName)s() - %(message)s\\')\\nh.setFormatter(f2)\\nlogger.critical(\"Help Help\")',\n",
|
|
" '_i24': 'test_logging()',\n",
|
|
" '_i25': 'logging.basicConfig(force=True)\\ntest_logging()',\n",
|
|
" '_i26': '__name__',\n",
|
|
" '_26': '__main__',\n",
|
|
" '_i27': 'logger = logging.getLogger(__name__)',\n",
|
|
" '_i28': 'logger.warning(\"Hi\")',\n",
|
|
" '_i29': 'import sys\\nh2 = logging.StreamHandler(sys.stdout)',\n",
|
|
" 'sys': <module 'sys' (built-in)>,\n",
|
|
" 'h2': <StreamHandler stdout (NOTSET)>,\n",
|
|
" '_i30': 'logger = logging.getLogger(__name__)\\nlogger.handlers.append(h2)',\n",
|
|
" '_i31': 'logger.error(\"Hi\")',\n",
|
|
" '_i32': '%cd demo/Software_Engineering/citation_network/',\n",
|
|
" '_i33': '%run -p citation_network_slow.py',\n",
|
|
" 'load_citations': <function __main__.load_citations(filename, header_size=0)>,\n",
|
|
" 'build_index': <function __main__.build_index(citations, reverse=False)>,\n",
|
|
" 'citation_counts': <function __main__.citation_counts(reverse_index)>,\n",
|
|
" 'get_percentiles': <function __main__.get_percentiles(papers_with_counts, n_percentiles)>,\n",
|
|
" 'value_at_rank': <function __main__.value_at_rank(sorted_values, rank)>,\n",
|
|
" 'make_percentiles_table': <function __main__.make_percentiles_table(percentiles)>,\n",
|
|
" 'main': <function __main__.main(citation_filename, header_size, percentiles)>,\n",
|
|
" '_i34': '%run -p citation_network_fix.py',\n",
|
|
" '_i35': '(.48 - .37) / .48',\n",
|
|
" '_35': 0.22916666666666666,\n",
|
|
" '_i36': 'pwd',\n",
|
|
" '_36': '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/Software_Engineering/citation_network',\n",
|
|
" '_i37': 'cd ..',\n",
|
|
" '_i38': 'cd ../pdb/',\n",
|
|
" '_i39': 'ls',\n",
|
|
" '_exit_code': 0,\n",
|
|
" '_i40': '%debug',\n",
|
|
" '_i41': '%pdb',\n",
|
|
" '_i42': '%run middle.py',\n",
|
|
" 'get_middle': <function __main__.get_middle(item_list)>,\n",
|
|
" 'make_list': <function __main__.make_list(size=0)>,\n",
|
|
" 'run': <function __main__.run()>,\n",
|
|
" '_i43': 'import middle',\n",
|
|
" 'middle': <module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>,\n",
|
|
" '_i44': 'middle.run()',\n",
|
|
" '_i45': 'from importlib import reload\\nreload(middle)',\n",
|
|
" 'reload': <function importlib.reload(module)>,\n",
|
|
" '_45': <module 'middle' from '/Users/timdiller/Documents/Diller_Digital_SWNG/demo/pdb/middle.py'>,\n",
|
|
" '_i46': 'middle.run()',\n",
|
|
" '_i47': 'locals()'}"
|
|
]
|
|
},
|
|
"execution_count": 47,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"locals()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "da1ada4c-dde6-4eb5-a0b1-f63ac5294190",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Lecture 7 - Unit Testing"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 48,
|
|
"id": "a31a99eb-20ff-4bff-8b1e-a86dd5dcc792",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def simple_div(a,b):\n",
|
|
" return a / b"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"id": "622126db-8a6d-4971-b020-1be1b325b4a5",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"5.0"
|
|
]
|
|
},
|
|
"execution_count": 50,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"simple_div(25,5)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 51,
|
|
"id": "51b40fe1-6918-4405-bce6-6f4bb5e5bb22",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"True"
|
|
]
|
|
},
|
|
"execution_count": 51,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"simple_div(25,5) == 5"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 52,
|
|
"id": "16dc6859-ece8-4f97-8c9a-d877c3c73e4d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"assert True"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 54,
|
|
"id": "ef15518b-aaf8-4cdf-afe1-5d96f6ea396b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Automatic pdb calling has been turned OFF\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%pdb"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"id": "a0886220-4b61-4ab0-bc04-8adae3604a88",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "AssertionError",
|
|
"evalue": "",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
|
"\u001b[31mAssertionError\u001b[39m Traceback (most recent call last)",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[55]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n",
|
|
"\u001b[31mAssertionError\u001b[39m: "
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"assert False"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 60,
|
|
"id": "2b4d383c-4708-4c33-9186-270ba5c4b6f1",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "ZeroDivisionError",
|
|
"evalue": "division by zero",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
|
"\u001b[31mZeroDivisionError\u001b[39m Traceback (most recent call last)",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[60]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m simple_div(\u001b[32m25\u001b[39m,\u001b[32m5\u001b[39m) == \u001b[32m5\u001b[39m\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m simple_div(\u001b[32m1\u001b[39m, \u001b[32m3\u001b[39m) == \u001b[32m0.3333333333333333333\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m \u001b[43msimple_div\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[48]\u001b[39m\u001b[32m, line 2\u001b[39m, in \u001b[36msimple_div\u001b[39m\u001b[34m(a, b)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34msimple_div\u001b[39m(a,b):\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m\n",
|
|
"\u001b[31mZeroDivisionError\u001b[39m: division by zero"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"assert simple_div(25,5) == 5\n",
|
|
"assert simple_div(1, 3) == 0.3333333333333333333\n",
|
|
"assert simple_div(1, 0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c6547535-df7f-4f4a-9c14-a890943a8415",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"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",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.8"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|