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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x1097864e0>,)\n"
]
}
],
"source": [
"import ptvsd\n",
"\n",
"from ptvsd import session\n",
"from ptvsd.socket import create_server, create_client\n",
"from ptvsd.messaging import JsonIOStream, JsonMessageChannel, MessageHandlers\n",
"\n",
"import socket\n",
"\n",
"HOST = 'localhost' # Standard loopback interface address (localhost)\n",
"PORT = 9876 # Port to listen on (non-privileged ports are > 1023)\n",
"\n",
"conn = create_client()\n",
"conn.connect(('localhost', PORT))\n",
"events = {}\n",
"\n",
"def make_handler(name):\n",
" events[name] = []\n",
" def invoke(*args):\n",
" events[name].append(args[0])\n",
" print(name, args)\n",
" return invoke\n",
"handlers = MessageHandlers(output=make_handler('output'), event=make_handler('event'))\n",
"\n",
"stream = JsonIOStream.from_socket(conn, 'root-process')\n",
"channel = JsonMessageChannel(stream, handlers=handlers)\n",
"channel.start()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ptvsd.messaging.OutgoingRequest at 0x109786a90>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x1096ac128>,)\n",
"event (<ptvsd.messaging.Event object at 0x109786080>,)\n",
"event (<ptvsd.messaging.Event object at 0x1093c2ef0>,)\n",
"event (<ptvsd.messaging.Event object at 0x109786978>,)\n",
"event (<ptvsd.messaging.Event object at 0x109765fd0>,)\n",
"event (<ptvsd.messaging.Event object at 0x109786ac8>,)\n"
]
}
],
"source": [
"channel.send_request('attach', arguments={'justMyCode': False, \"debugOptions\": [\n",
" \"DebugStdLib\",\n",
" \"RedirectOutput\",\n",
" \"UnixClient\",\n",
" \"ShowReturnValue\"\n",
" ]})"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ptvsd.messaging.OutgoingRequest at 0x109ee3828>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source = {\n",
" 'name': f'test2.py',\n",
" 'path': f'/private/tmp/test.py'\n",
"}\n",
"breakpoints = [{\n",
" 'line': 2 \n",
"}]\n",
"channel.send_request('setBreakpoints', arguments={'breakpoints': breakpoints, 'source': source,\n",
" 'lines': [2], \"sourceModified\": False})"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# channel.send_request('setBreakpoints', arguments={'breakpoints': [], 'source': source,\n",
"# 'lines': [], \"sourceModified\": False})"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x109eca860>,)\n"
]
}
],
"source": [
"# source = {\n",
"# 'name': f'test.py',\n",
"# 'sourceReference': 1\n",
"# }\n",
"# breakpoints = [{\n",
"# 'line': 2 \n",
"# }]\n",
"# channel.send_request('setBreakpoints', arguments={'breakpoints': breakpoints, 'source': source,\n",
"# 'lines': [2], \"sourceModified\": False})"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x109f2ce10>,)\n"
]
},
{
"data": {
"text/plain": [
"<ptvsd.messaging.OutgoingRequest at 0x109f46da0>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x109ed1d68>,)\n"
]
}
],
"source": [
"channel.send_request('next', arguments={'threadId': 1})"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ptvsd.messaging.OutgoingRequest at 0x109f46fd0>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"event (<ptvsd.messaging.Event object at 0x109f46cc0>,)\n",
"event (<ptvsd.messaging.Event object at 0x109ed1cc0>,)\n",
"event (<ptvsd.messaging.Event object at 0x109f46780>,)\n",
"event (<ptvsd.messaging.Event object at 0x109f46c88>,)\n"
]
}
],
"source": [
"channel.send_request('continue', arguments={'threadId': 1})"
]
},
{
"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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment