|
707 | 707 | " for x in o.display_objects: res.append(_mk_out(x.data, x.metadata))\n", |
708 | 708 | " if r is not None and not o.quiet:\n", |
709 | 709 | " res.append(_mk_out(*fmt.format(r), 'execute_result'))\n", |
| 710 | + " if 'execution_count' not in o: o['execution_count']=None\n", |
| 711 | + " for p in res: p['execution_count'] = o['execution_count']\n", |
710 | 712 | " return res" |
711 | 713 | ] |
712 | 714 | }, |
|
747 | 749 | { |
748 | 750 | "data": { |
749 | 751 | "text/plain": [ |
750 | | - "[{'name': 'stdout', 'output_type': 'stream', 'text': ['1\\n']}]" |
| 752 | + "[{'name': 'stdout',\n", |
| 753 | + " 'output_type': 'stream',\n", |
| 754 | + " 'text': ['1\\n'],\n", |
| 755 | + " 'execution_count': None}]" |
751 | 756 | ] |
752 | 757 | }, |
753 | 758 | "execution_count": null, |
|
776 | 781 | "text/plain": [ |
777 | 782 | "[{'name': 'stdout',\n", |
778 | 783 | " 'output_type': 'stream',\n", |
779 | | - " 'text': ['CPU times: user 1 us, sys: 1 us, total: 2 us\\n',\n", |
780 | | - " 'Wall time: 3.1 us\\n']},\n", |
| 784 | + " 'text': ['CPU times: user 1 us, sys: 0 ns, total: 1 us\\n',\n", |
| 785 | + " 'Wall time: 4.05 us\\n'],\n", |
| 786 | + " 'execution_count': None},\n", |
781 | 787 | " {'data': {'text/plain': ['2']},\n", |
782 | 788 | " 'metadata': {},\n", |
783 | | - " 'output_type': 'execute_result'}]" |
| 789 | + " 'output_type': 'execute_result',\n", |
| 790 | + " 'execution_count': None}]" |
784 | 791 | ] |
785 | 792 | }, |
786 | 793 | "execution_count": null, |
|
862 | 869 | " 'File \\x1b[0;32m<ipython-input-1-9e1622b385b6>:1\\x1b[0m\\n',\n", |
863 | 870 | " '\\x1b[0;32m----> 1\\x1b[0m \\x1b[38;5;241m1\\x1b[39m\\x1b[38;5;241m/\\x1b[39m\\x1b[38;5;241m0\\x1b[39m\\n',\n", |
864 | 871 | " '\\n',\n", |
865 | | - " '\\x1b[0;31mZeroDivisionError\\x1b[0m: division by zero\\n']},\n", |
| 872 | + " '\\x1b[0;31mZeroDivisionError\\x1b[0m: division by zero\\n'],\n", |
| 873 | + " 'execution_count': None},\n", |
866 | 874 | " {'ename': 'ZeroDivisionError',\n", |
867 | 875 | " 'evalue': 'division by zero',\n", |
868 | 876 | " 'output_type': 'error',\n", |
869 | | - " 'traceback': 'Traceback (most recent call last):\\n File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n File \"<ipython-input-1-9e1622b385b6>\", line 1, in <module>\\n 1/0\\n ~^~\\nZeroDivisionError: division by zero\\n'}]" |
| 877 | + " 'traceback': 'Traceback (most recent call last):\\n File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n File \"<ipython-input-1-9e1622b385b6>\", line 1, in <module>\\n 1/0\\n ~^~\\nZeroDivisionError: division by zero\\n',\n", |
| 878 | + " 'execution_count': None}]" |
870 | 879 | ] |
871 | 880 | }, |
872 | 881 | "execution_count": null, |
|
887 | 896 | { |
888 | 897 | "data": { |
889 | 898 | "text/plain": [ |
890 | | - "[{'name': 'stdout', 'output_type': 'stream', 'text': ['no timeout\\n']}]" |
| 899 | + "[{'name': 'stdout',\n", |
| 900 | + " 'output_type': 'stream',\n", |
| 901 | + " 'text': ['no timeout\\n'],\n", |
| 902 | + " 'execution_count': None}]" |
891 | 903 | ] |
892 | 904 | }, |
893 | 905 | "execution_count": null, |
|
947 | 959 | "text/plain": [ |
948 | 960 | "[{'data': {'text/plain': ['2']},\n", |
949 | 961 | " 'metadata': {},\n", |
950 | | - " 'output_type': 'execute_result'}]" |
| 962 | + " 'output_type': 'execute_result',\n", |
| 963 | + " 'execution_count': None}]" |
951 | 964 | ] |
952 | 965 | }, |
953 | 966 | "execution_count": null, |
|
1013 | 1026 | "----> 1 import time; time.sleep(1.1)\n", |
1014 | 1027 | "\n", |
1015 | 1028 | "Cell In[6], line 7, in run_cell.<locals>.handler(*args)\n", |
1016 | | - " 5 if not timeout: timeout = self.timeout\n", |
1017 | | - " 6 if timeout:\n", |
1018 | | - "----> 7 def handler(*args): raise TimeoutError()\n", |
1019 | | - " 8 signal.signal(signal.SIGALRM, handler)\n", |
1020 | | - " 9 signal.alarm(timeout)\n", |
| 1029 | + "----> 7 def handler(*args): raise TimeoutError()\n", |
1021 | 1030 | "\n", |
1022 | 1031 | "TimeoutError: \n", |
1023 | 1032 | "</code></pre>\n" |
|
1056 | 1065 | "<span class=\"ansi-green-fg\">----> 1</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">import</span> <span class=\"ansi-bold\" style=\"color: rgb(0,0,255)\">time</span>; time<span style=\"color: rgb(98,98,98)\">.</span>sleep(<span style=\"color: rgb(98,98,98)\">1.1</span>)\n", |
1057 | 1066 | "\n", |
1058 | 1067 | "Cell <span class=\"ansi-green-fg\">In[6], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.<locals>.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n", |
1059 | | - "<span class=\"ansi-green-intense-fg ansi-bold\"> 5</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">if</span> <span class=\"ansi-bold\" style=\"color: rgb(175,0,255)\">not</span> timeout: timeout <span style=\"color: rgb(98,98,98)\">=</span> <span style=\"color: rgb(0,135,0)\">self</span><span style=\"color: rgb(98,98,98)\">.</span>timeout\n", |
1060 | | - "<span class=\"ansi-green-intense-fg ansi-bold\"> 6</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">if</span> timeout:\n", |
1061 | | - "<span class=\"ansi-green-fg\">----> 7</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">def</span> <span style=\"color: rgb(0,0,255)\">handler</span>(<span style=\"color: rgb(98,98,98)\">*</span>args): <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">raise</span> <span class=\"ansi-bold\" style=\"color: rgb(215,95,95)\">TimeoutError</span>()\n", |
1062 | | - "<span class=\"ansi-green-intense-fg ansi-bold\"> 8</span> signal<span style=\"color: rgb(98,98,98)\">.</span>signal(signal<span style=\"color: rgb(98,98,98)\">.</span>SIGALRM, handler)\n", |
1063 | | - "<span class=\"ansi-green-intense-fg ansi-bold\"> 9</span> signal<span style=\"color: rgb(98,98,98)\">.</span>alarm(timeout)\n", |
| 1068 | + "<span class=\"ansi-green-fg\">----> 7</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">def</span> <span style=\"color: rgb(0,0,255)\">handler</span>(<span style=\"color: rgb(98,98,98)\">*</span>args): <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">raise</span> <span class=\"ansi-bold\" style=\"color: rgb(215,95,95)\">TimeoutError</span>()\n", |
1064 | 1069 | "\n", |
1065 | 1070 | "<span class=\"ansi-red-fg\">TimeoutError</span>: \n", |
1066 | 1071 | "</code></pre>\n" |
|
1134 | 1139 | " 'File \\x1b[0;32m<ipython-input-1-01648acb07bd>:1\\x1b[0m\\n',\n", |
1135 | 1140 | " '\\x1b[0;32m----> 1\\x1b[0m \\x1b[38;5;28;01mraise\\x1b[39;00m \\x1b[38;5;167;01mException\\x1b[39;00m(\\x1b[38;5;124m\"\\x1b[39m\\x1b[38;5;124mOops\\x1b[39m\\x1b[38;5;124m\"\\x1b[39m)\\n',\n", |
1136 | 1141 | " '\\n',\n", |
1137 | | - " '\\x1b[0;31mException\\x1b[0m: Oops\\n']},\n", |
| 1142 | + " '\\x1b[0;31mException\\x1b[0m: Oops\\n'],\n", |
| 1143 | + " 'execution_count': None},\n", |
1138 | 1144 | " {'ename': 'Exception',\n", |
1139 | 1145 | " 'evalue': 'Oops',\n", |
1140 | 1146 | " 'output_type': 'error',\n", |
1141 | | - " 'traceback': 'Traceback (most recent call last):\\n File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n File \"<ipython-input-1-01648acb07bd>\", line 1, in <module>\\n raise Exception(\"Oops\")\\nException: Oops\\n'}]" |
| 1147 | + " 'traceback': 'Traceback (most recent call last):\\n File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n File \"<ipython-input-1-01648acb07bd>\", line 1, in <module>\\n raise Exception(\"Oops\")\\nException: Oops\\n',\n", |
| 1148 | + " 'execution_count': None}]" |
1142 | 1149 | ] |
1143 | 1150 | }, |
1144 | 1151 | "execution_count": null, |
|
1184 | 1191 | " if cell.cell_type!='code': return\n", |
1185 | 1192 | " self._cell_idx = cell.idx_ + 1\n", |
1186 | 1193 | " outs = self.run(cell.source)\n", |
1187 | | - " if outs:\n", |
1188 | | - " cell.outputs = _dict2obj(outs)\n", |
1189 | | - " for o in outs:\n", |
1190 | | - " if 'execution_count' in o: cell['execution_count'] = o['execution_count']" |
| 1194 | + " if outs: cell.outputs = _dict2obj(outs)" |
1191 | 1195 | ] |
1192 | 1196 | }, |
1193 | 1197 | { |
|
1238 | 1242 | { |
1239 | 1243 | "data": { |
1240 | 1244 | "text/plain": [ |
1241 | | - "[{'name': 'stdout', 'output_type': 'stream', 'text': ['1\\n']},\n", |
| 1245 | + "[{'name': 'stdout',\n", |
| 1246 | + " 'output_type': 'stream',\n", |
| 1247 | + " 'text': ['1\\n'],\n", |
| 1248 | + " 'execution_count': None},\n", |
1242 | 1249 | " {'data': {'text/plain': ['2']},\n", |
1243 | 1250 | " 'metadata': {},\n", |
1244 | | - " 'output_type': 'execute_result'}]" |
| 1251 | + " 'output_type': 'execute_result',\n", |
| 1252 | + " 'execution_count': None}]" |
1245 | 1253 | ] |
1246 | 1254 | }, |
1247 | 1255 | "execution_count": null, |
|
0 commit comments