[Pkg-bitcoin-commits] [python-quamash] 174/269: Fixed ProcessPoolExecutor handling Exceptions

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:29 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 9a1b1af9128407bfc3b2d012d35f1fcf0859c9a8
Author: Mark Harviston <mark.harviston at gmail.com>
Date:   Mon Dec 22 10:55:35 2014 -0800

    Fixed ProcessPoolExecutor handling Exceptions
    
    multiprocessing can only handle pickleable objects.
    
    The way TestException was structured (using a fixture factory function
    and a closure) wasn't pickle friendly, just making TestException top-level is.
    
    To be clear the problem was in the tests not in the code.
---
 tests/test_qeventloop.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index ed4ca0f..9ab4857 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -70,11 +70,7 @@ def executor(request):
 	request.addfinalizer(exc.shutdown)
 	return exc
 
-
- at pytest.fixture
-def TestException():
-	class TestException(Exception): pass  # pep8ignore
-	return TestException
+class TestException(Exception): pass
 
 class TestCanRunTasksInExecutor:
 	"""
@@ -96,20 +92,21 @@ class TestCanRunTasksInExecutor:
 
 		assert was_invoked.value == 1
 
-	def test_can_handle_exception_in_executor(self, TestException, loop, executor):
-		if isinstance(executor, ProcessPoolExecutor):
-			pytest.xfail("can't catch ProcessPoolExecutor exceptions (yet)")
-
+	def test_can_handle_exception_in_executor(self, loop, executor):
 		with pytest.raises(TestException) as excinfo:
 			loop.run_until_complete(asyncio.wait_for(
-				loop.run_in_executor(executor, self.blocking_failure, TestException),
+				loop.run_in_executor(executor, self.blocking_failure),
 				timeout=3.0,
 			))
 
 		assert str(excinfo.value) == 'Testing'
 
-	def blocking_failure(self, TestException):
-		raise TestException('Testing')
+	def blocking_failure(self):
+		logging.debug('raising')
+		try:
+			raise TestException('Testing')
+		finally:
+			logging.debug('raised!')
 
 	def blocking_func(self, was_invoked):
 		logging.debug('start blocking_func()')

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