commit: b3b15c451cc21a2c53638f0eacc8396e395dcab3 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Mon May 7 06:24:22 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Mon May 7 06:28:47 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b3b15c45
retry: add loop parameter during decoration pym/portage/sync/modules/rsync/rsync.py | 2 +- pym/portage/tests/util/futures/test_retry.py | 16 ++++++++-------- pym/portage/util/futures/retry.py | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py index 1b8941ff6..070798a53 100644 --- a/pym/portage/sync/modules/rsync/rsync.py +++ b/pym/portage/sync/modules/rsync/rsync.py @@ -173,7 +173,7 @@ class RsyncSync(NewBase): loop = global_event_loop() func_coroutine = functools.partial(loop.run_in_executor, None, noisy_refresh_keys) - decorated_func = retry_decorator(func_coroutine) + decorated_func = retry_decorator(func_coroutine, loop=loop) loop.run_until_complete(decorated_func()) out.eend(0) except (GematoException, asyncio.TimeoutError) as e: diff --git a/pym/portage/tests/util/futures/test_retry.py b/pym/portage/tests/util/futures/test_retry.py index 16ecccbc7..7a1e76280 100644 --- a/pym/portage/tests/util/futures/test_retry.py +++ b/pym/portage/tests/util/futures/test_retry.py @@ -85,7 +85,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(SucceedLater(1)) decorator = retry(try_max=9999, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) result = loop.run_until_complete(decorated_func()) self.assertEqual(result, 'success') @@ -94,7 +94,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(SucceedNever()) decorator = retry(try_max=4, try_timeout=None, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) @@ -104,7 +104,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(SucceedNever()) decorator = retry(reraise=True, try_max=4, try_timeout=None, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception(), SucceedNeverException)) @@ -114,7 +114,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(HangForever()) decorator = retry(try_max=2, try_timeout=0.1, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) @@ -124,7 +124,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(HangForever()) decorator = retry(reraise=True, try_max=2, try_timeout=0.1, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception(), asyncio.TimeoutError)) @@ -134,7 +134,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(SucceedNever()) decorator = retry(try_timeout=0.1, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) future = decorated_func() loop.call_later(0.3, future.cancel) done, pending = loop.run_until_complete(asyncio.wait([future], loop=loop)) @@ -146,7 +146,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(SucceedNever()) decorator = retry(try_timeout=0.1, overall_timeout=0.3, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) @@ -157,7 +157,7 @@ class RetryTestCase(TestCase): func_coroutine = self._wrap_coroutine_func(HangForever()) decorator = retry(try_timeout=0.1, overall_timeout=0.3, delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) - decorated_func = decorator(func_coroutine) + decorated_func = decorator(func_coroutine, loop=loop) done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) self.assertEqual(len(done), 1) self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) diff --git a/pym/portage/util/futures/retry.py b/pym/portage/util/futures/retry.py index 8a51669ff..ccfc087ab 100644 --- a/pym/portage/util/futures/retry.py +++ b/pym/portage/util/futures/retry.py @@ -49,12 +49,12 @@ def retry(try_max=None, try_timeout=None, overall_timeout=None, overall_timeout, delay_func, reraise) -def _retry_wrapper(loop, try_max, try_timeout, overall_timeout, delay_func, - reraise, func): +def _retry_wrapper(_loop, try_max, try_timeout, overall_timeout, delay_func, + reraise, func, loop=None): """ Create and return a decorated function. """ - return functools.partial(_retry, loop, try_max, try_timeout, + return functools.partial(_retry, loop or _loop, try_max, try_timeout, overall_timeout, delay_func, reraise, func)