[Pkg-bitcoin-commits] [python-quamash] 164/269: docstring/style update
Jonas Smedegaard
dr at jones.dk
Fri Nov 24 11:26:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository python-quamash.
commit 962657e1e43db6282b78da57a6418b700cf44d90
Author: Mark Harviston <mark.harviston at gmail.com>
Date: Sun Dec 14 04:41:44 2014 -0800
docstring/style update
---
quamash/__init__.py | 34 +++++++++++++++++++++++-----------
quamash/_common.py | 1 +
quamash/_unix.py | 5 +++++
quamash/_windows.py | 8 ++++++++
tests/test_qeventloop.py | 9 +++------
5 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/quamash/__init__.py b/quamash/__init__.py
index 7bdac70..3b30986 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -1,9 +1,8 @@
# © 2014 Mark Harviston <mark.harviston at gmail.com>
# © 2014 Arve Knudsen <arve.knudsen at gmail.com>
# BSD License
-"""
-Implementation of the PEP 3156 Event-Loop with Qt
-"""
+""" Implementation of the PEP 3156 Event-Loop with Qt. """
+
__author__ = 'Mark Harviston <mark.harviston at gmail.com>, Arve Knudsen <arve.knudsen at gmail.com>'
__version__ = '0.3'
__license__ = 'BSD'
@@ -56,11 +55,13 @@ from ._common import with_logger
@with_logger
class _QThreadWorker(QtCore.QThread):
+
"""
Read from the queue.
For use by the QThreadExecutor
"""
+
def __init__(self, queue, num):
self.__queue = queue
self.__stop = False
@@ -102,8 +103,10 @@ class _QThreadWorker(QtCore.QThread):
@with_logger
class QThreadExecutor(QtCore.QObject):
+
"""
- ThreadExecutor that produces QThreads
+ ThreadExecutor that produces QThreads.
+
Same API as `concurrent.futures.Executor`
>>> from quamash import QThreadExecutor
@@ -112,6 +115,7 @@ class QThreadExecutor(QtCore.QObject):
... r = f.result()
... assert r == 4
"""
+
def __init__(self, max_workers=10, parent=None):
super().__init__(parent)
self.__max_workers = max_workers
@@ -160,10 +164,11 @@ class QThreadExecutor(QtCore.QObject):
def _easycallback(fn):
"""
- Decorator that wraps a callback in a signal, and packs & unpacks arguments,
- Makes the wrapped function effectively threadsafe. If you call the function
- from one thread, it will be executed in the thread the QObject has affinity
- with.
+ Decorator that wraps a callback in a signal.
+
+ It also packs & unpacks arguments, and makes the wrapped function effectively
+ threadsafe. If you call the function from one thread, it will be executed in
+ the thread the QObject has affinity with.
Remember: only objects that inherit from QObject can support signals/slots
@@ -219,8 +224,9 @@ else:
@with_logger
class QEventLoop(_baseclass):
+
"""
- Implementation of asyncio event loop that uses the Qt Event loop
+ Implementation of asyncio event loop that uses the Qt Event loop.
>>> import quamash, asyncio
>>> from quamash import QtCore, QtGui, QApplication
@@ -235,6 +241,7 @@ class QEventLoop(_baseclass):
>>> with QEventLoop(app) as loop:
... loop.run_until_complete(xplusy(2, 2))
"""
+
def __init__(self, app=None):
self.__timers = []
self.__app = app or QApplication.instance()
@@ -290,11 +297,15 @@ class QEventLoop(_baseclass):
self._logger.debug('Stopped event loop')
def is_running(self):
- """Is event loop running?"""
+ """Return True if the event loop is running, False otherwise."""
return self.__is_running
def close(self):
- """Close event loop."""
+ """
+ Release all resources used by the event loop.
+
+ The loop cannot be restarted after it has been closed.
+ """
self._logger.debug('Closing event loop...')
if self.__default_executor is not None:
self.__default_executor.shutdown()
@@ -335,6 +346,7 @@ class QEventLoop(_baseclass):
return _Cancellable(timer, self)
def call_soon(self, callback, *args):
+ """Register a callback to be run on the next iteration of the event loop."""
return self.call_later(0, callback, *args)
def call_at(self, when, callback, *args):
diff --git a/quamash/_common.py b/quamash/_common.py
index 16c9090..604e2e9 100644
--- a/quamash/_common.py
+++ b/quamash/_common.py
@@ -1,6 +1,7 @@
# © 2014 Mark Harviston <mark.harviston at gmail.com>
# © 2014 Arve Knudsen <arve.knudsen at gmail.com>
# BSD License
+""" Mostly irrelevant, but useful utilities common to UNIX and Windows. """
import logging
diff --git a/quamash/_unix.py b/quamash/_unix.py
index 320cdd6..442bfe4 100644
--- a/quamash/_unix.py
+++ b/quamash/_unix.py
@@ -1,6 +1,9 @@
# © 2014 Mark Harviston <mark.harviston at gmail.com>
# © 2014 Arve Knudsen <arve.knudsen at gmail.com>
# BSD License
+
+""" UNIX specific Quamash functionality. """
+
import asyncio
from asyncio import selectors
import collections
@@ -37,7 +40,9 @@ def _fileobj_to_fd(fileobj):
class _SelectorMapping(collections.Mapping):
+
"""Mapping of file objects to selector keys."""
+
def __init__(self, selector):
self._selector = selector
diff --git a/quamash/_windows.py b/quamash/_windows.py
index e44040b..523c933 100644
--- a/quamash/_windows.py
+++ b/quamash/_windows.py
@@ -1,7 +1,11 @@
# © 2014 Mark Harviston <mark.harviston at gmail.com>
# © 2014 Arve Knudsen <arve.knudsen at gmail.com>
# BSD License
+
+"""Windows specific Quamash functionality."""
+
import asyncio
+
try:
import _winapi
from asyncio import windows_events
@@ -16,7 +20,9 @@ from ._common import with_logger
class _ProactorEventLoop(QtCore.QObject, asyncio.ProactorEventLoop):
+
"""Proactor based event loop."""
+
def __init__(self):
QtCore.QObject.__init__(self)
asyncio.ProactorEventLoop.__init__(self, _IocpProactor())
@@ -140,7 +146,9 @@ class _EventWorker(QtCore.QThread):
@with_logger
class _EventPoller(QtCore.QObject):
+
"""Polling of events in separate thread."""
+
sig_events = QtCore.Signal(list)
def start(self, proactor):
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 5685f23..34bf65d 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -73,7 +73,7 @@ def executor(request):
@pytest.fixture
def TestException():
- class TestException(Exception): pass
+ class TestException(Exception): pass # pep8ignore
return TestException
class TestCanRunTasksInExecutor:
@@ -105,7 +105,7 @@ class TestCanRunTasksInExecutor:
loop.run_in_executor(executor, self.blocking_failure, TestException),
timeout=3.0,
))
-
+
assert str(excinfo.value) == 'Testing'
def blocking_failure(self, TestException):
@@ -162,23 +162,20 @@ def test_can_read_subprocess(loop):
import subprocess
@asyncio.coroutine
def mycoro():
- #nonlocal process, received_stdout
process = yield from asyncio.create_subprocess_exec(
sys.executable or 'python', '-c', 'print("Hello async world!")', stdout=subprocess.PIPE)
received_stdout = yield from process.stdout.readexactly(len(b'Hello async world!\n'))
- #received_stdout, received_stderr = yield from process.communicate()
- #received_stdout = yield from process.stdout.readline()
yield from process.wait()
assert process.returncode == 0
assert received_stdout == b'Hello async world!\n'
loop.run_until_complete(asyncio.wait_for(mycoro(), timeout=3))
+
def test_can_communicate_subprocess(loop):
"""Verify that a subprocess's data can be passed in/out via stdin/stdout."""
import subprocess
@asyncio.coroutine
def mycoro():
- #nonlocal process, received_stdout
process = yield from asyncio.create_subprocess_exec(
sys.executable or 'python', '-c', 'print(input())', stdout=subprocess.PIPE, stdin=subprocess.PIPE)
received_stdout, received_stderr = yield from process.communicate(b'Hello async world!\n')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git
More information about the Pkg-bitcoin-commits
mailing list