Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from ericsnowcurrently/lint
Browse files Browse the repository at this point in the history
Fix flake8 failures.
  • Loading branch information
ericsnowcurrently authored Jan 10, 2018
2 parents 4cdd5f5 + 0b4367d commit 5e718ae
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 152 deletions.
3 changes: 2 additions & 1 deletion ptvsd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "4.0.0a1"
12 changes: 9 additions & 3 deletions ptvsd/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

import pydevd

import ptvsd.wrapper


__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "4.0.0a1"


if __name__ == '__main__':
import ptvsd.wrapper
import pydevd
ptvsd.wrapper.install()
pydevd.main()
22 changes: 17 additions & 5 deletions ptvsd/debugger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

import sys

import pydevd

import ptvsd.wrapper


__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "4.0.0a1"

DONT_DEBUG = []


def debug(filename, port_num, debug_id, debug_options, run_as):
import sys
import ptvsd.wrapper
import pydevd
sys.argv[1:0] = ['--port', str(port_num), '--client', '127.0.0.1', '--file', filename]
# TODO: docstring
ptvsd.wrapper.install()
sys.argv[1:0] = [
'--port', str(port_num),
'--client', '127.0.0.1',
'--file', filename,
]
pydevd.main()
43 changes: 34 additions & 9 deletions ptvsd/futures.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,94 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

from __future__ import print_function, with_statement, absolute_import

__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "4.0.0a1"

import sys
import threading
import traceback
from ptvsd.reraise import reraise


__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "4.0.0a1"


class Future(object):
# TODO: docstring

def __init__(self, loop):
self._lock = threading.Lock()
self._loop = loop
self._done = False
self._observed = False
self._done_callbacks = []
self._exc_info = None

def __del__(self):
with self._lock:
if self._done and self._exc_info and not self._observed:
print('Unobserved exception in a Future:', file=sys.__stderr__)
traceback.print_exception(self._exc_info[0], self._exc_info[1], self._exc_info[2], file=sys.__stderr__)
traceback.print_exception(*self._exc_info, file=sys.__stderr__)

def result(self):
# TODO: docstring
with self._lock:
self._observed = True
if self._exc_info:
reraise(self._exc_info)
return self._result

def exc_info(self):
# TODO: docstring
with self._lock:
self._observed = True
return self._exc_info

def set_result(self, result):
# TODO: docstring
with self._lock:
self._result = result
self._exc_info = None
self._done = True
callbacks = list(self._done_callbacks)

def invoke_callbacks():
for cb in callbacks:
cb(self)

self._loop.call_soon(invoke_callbacks)

def set_exc_info(self, exc_info):
# TODO: docstring
with self._lock:
self._exc_info = exc_info
self._done = True
callbacks = list(self._done_callbacks)

def invoke_callbacks():
for cb in callbacks:
cb(self)

self._loop.call_soon(invoke_callbacks)

def add_done_callback(self, callback):
# TODO: docstring
with self._lock:
done = self._done
self._done_callbacks.append(callback)
if done:
callback(self)

def remove_done_callback(self, callback):
# TODO: docstring
with self._lock:
self._done_callbacks.remove(callback)


class EventLoop(object):
# TODO: docstring

def __init__(self):
self._queue = []
self._lock = threading.Lock()
Expand All @@ -89,7 +107,7 @@ def run_forever(self):
self._event.clear()
for (f, args) in queue:
f(*args)

def call_soon(self, f, *args):
with self._lock:
self._queue.append((f, args))
Expand All @@ -100,26 +118,32 @@ def call_soon_threadsafe(self, f, *args):


class Result(object):
# TODO: docstring

__slots__ = ['value']

def __init__(self, value):
self.value = value


def async(f):
# TODO: docstring

def g(self, loop, *args, **kwargs):
it = f(self, *args, **kwargs)
result = Future(loop)
if it is None:
result.set_result(None)
return result

def callback(fut):
try:
if fut is None:
x = next(it)
else:
exc_info = fut.exc_info()
if exc_info:
x = it.throw(exc_info[0], exc_info[1], exc_info[2])
x = it.throw(*exc_info)
else:
x = it.send(fut.result())
except StopIteration:
Expand All @@ -131,6 +155,7 @@ def callback(fut):
result.set_result(x.value)
else:
x.add_done_callback(callback)

callback(None)
return result
return g
Loading

0 comments on commit 5e718ae

Please sign in to comment.