[Pkg-bitcoin-commits] [python-quamash] 20/269: Fix run_until_complete

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:12 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 187c1e2355b3bcd200c578a73d36069056721814
Author: Arve Knudsen <arve.knudsen at gmail.com>
Date:   Mon Jun 30 13:35:15 2014 +0200

    Fix run_until_complete
---
 quamash/__init__.py      |  7 +++++--
 tests/test_qeventloop.py | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/quamash/__init__.py b/quamash/__init__.py
index 6012354..4c06760 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -198,15 +198,18 @@ class QEventLoop(QtCore.QObject, _baseclass):
 
     def run_until_complete(self, future):
         """Run until Future is complete."""
+        self._logger.debug('Running {} until complete'.format(future))
         future = asyncio.async(future, loop=self)
-        future.add_done_callback(lambda *args: self.stop)
+        stop = lambda *args: self.stop()
+        future.add_done_callback(stop)
         try:
             self.run_forever()
         finally:
-            future.remove_done_callback(self.stop)
+            future.remove_done_callback(stop)
         if not future.done():
             raise RuntimeError('Event loop stopped before Future completed.')
 
+        self._logger.debug('Future {} finished running'.format(future))
         return future.result()
 
     def stop(self):
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
new file mode 100644
index 0000000..a6c75e1
--- /dev/null
+++ b/tests/test_qeventloop.py
@@ -0,0 +1,33 @@
+import asyncio
+import os.path
+import logging
+import sys
+from PyQt5.QtWidgets import QApplication
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
+import quamash
+
+
+logging.basicConfig(level=logging.DEBUG,
+                    format='%(asctime)s - %(levelname)s - %(name)s - %(message)s')
+
+
+class TestQEventLoop:
+    def test_can_run_tasks_in_default_executor(self):
+        """Verify that tasks can be run in default (threaded) executor."""
+        def blocking_func():
+            nonlocal was_invoked
+            was_invoked = True
+
+        @asyncio.coroutine
+        def blocking_task():
+            yield from loop.run_in_executor(None, blocking_func)
+
+        app = QApplication([])
+        was_invoked = False
+
+        loop = quamash.QEventLoop(app)
+        with loop:
+            loop.run_until_complete(blocking_task())
+
+        assert was_invoked
\ No newline at end of file

-- 
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