Skip to content

Instantly share code, notes, and snippets.

@maartenbreddels
Created May 29, 2019 11:58
Show Gist options
  • Save maartenbreddels/45a9e1b149d84a84b00768f8b578d9bf to your computer and use it in GitHub Desktop.
Save maartenbreddels/45a9e1b149d84a84b00768f8b578d9bf to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/maartenbreddels/miniconda3/envs/working/lib/python3.6/site-packages/ptvsd/_vendored/pydevd/pydevd_plugins/__init__.py:2: UserWarning: Module ipykernel was already imported from /Users/maartenbreddels/miniconda3/envs/working/lib/python3.6/site-packages/ipykernel/__init__.py, but /Users/maartenbreddels/src/ipython/ipykernel is being added to sys.path\n",
" __import__('pkg_resources').declare_namespace(__name__)\n"
]
}
],
"source": [
"import ptvsd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"ptvsd.enable_attach(('0.0.0.0', 9876), log_dir='/tmp/debugger/')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ptvsd.is_attached()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import IPython.core.compilerop as cop\n",
"import IPython"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# monkey patch IPython to lie about the filename\n",
"def code_name(code, number=0):\n",
" return \"/private/tmp/test.py\"\n",
"IPython.core.compilerop.code_name = code_name\n",
"# but also make sure the file exists (otherwise the debugger does not break)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting /private/tmp/test.py\n"
]
}
],
"source": [
"%%file /private/tmp/test.py\n",
"i = 0\n",
"print(i)\n",
"i += 10\n",
"print(i)\n",
"i += 10\n",
"print(i)\n",
"dsa"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"10\n",
"20\n"
]
},
{
"ename": "NameError",
"evalue": "name 'dsa' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/private/tmp/test.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mdsa\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'dsa' is not defined"
]
}
],
"source": [
"i = 0\n",
"print(i)\n",
"i += 10\n",
"print(i)\n",
"i += 10\n",
"print(i)\n",
"dsa"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment