1 |
commit: b3b15c451cc21a2c53638f0eacc8396e395dcab3 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon May 7 06:24:22 2018 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon May 7 06:28:47 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b3b15c45 |
7 |
|
8 |
retry: add loop parameter during decoration |
9 |
|
10 |
pym/portage/sync/modules/rsync/rsync.py | 2 +- |
11 |
pym/portage/tests/util/futures/test_retry.py | 16 ++++++++-------- |
12 |
pym/portage/util/futures/retry.py | 6 +++--- |
13 |
3 files changed, 12 insertions(+), 12 deletions(-) |
14 |
|
15 |
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py |
16 |
index 1b8941ff6..070798a53 100644 |
17 |
--- a/pym/portage/sync/modules/rsync/rsync.py |
18 |
+++ b/pym/portage/sync/modules/rsync/rsync.py |
19 |
@@ -173,7 +173,7 @@ class RsyncSync(NewBase): |
20 |
loop = global_event_loop() |
21 |
func_coroutine = functools.partial(loop.run_in_executor, |
22 |
None, noisy_refresh_keys) |
23 |
- decorated_func = retry_decorator(func_coroutine) |
24 |
+ decorated_func = retry_decorator(func_coroutine, loop=loop) |
25 |
loop.run_until_complete(decorated_func()) |
26 |
out.eend(0) |
27 |
except (GematoException, asyncio.TimeoutError) as e: |
28 |
|
29 |
diff --git a/pym/portage/tests/util/futures/test_retry.py b/pym/portage/tests/util/futures/test_retry.py |
30 |
index 16ecccbc7..7a1e76280 100644 |
31 |
--- a/pym/portage/tests/util/futures/test_retry.py |
32 |
+++ b/pym/portage/tests/util/futures/test_retry.py |
33 |
@@ -85,7 +85,7 @@ class RetryTestCase(TestCase): |
34 |
func_coroutine = self._wrap_coroutine_func(SucceedLater(1)) |
35 |
decorator = retry(try_max=9999, |
36 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
37 |
- decorated_func = decorator(func_coroutine) |
38 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
39 |
result = loop.run_until_complete(decorated_func()) |
40 |
self.assertEqual(result, 'success') |
41 |
|
42 |
@@ -94,7 +94,7 @@ class RetryTestCase(TestCase): |
43 |
func_coroutine = self._wrap_coroutine_func(SucceedNever()) |
44 |
decorator = retry(try_max=4, try_timeout=None, |
45 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
46 |
- decorated_func = decorator(func_coroutine) |
47 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
48 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
49 |
self.assertEqual(len(done), 1) |
50 |
self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) |
51 |
@@ -104,7 +104,7 @@ class RetryTestCase(TestCase): |
52 |
func_coroutine = self._wrap_coroutine_func(SucceedNever()) |
53 |
decorator = retry(reraise=True, try_max=4, try_timeout=None, |
54 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
55 |
- decorated_func = decorator(func_coroutine) |
56 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
57 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
58 |
self.assertEqual(len(done), 1) |
59 |
self.assertTrue(isinstance(done.pop().exception(), SucceedNeverException)) |
60 |
@@ -114,7 +114,7 @@ class RetryTestCase(TestCase): |
61 |
func_coroutine = self._wrap_coroutine_func(HangForever()) |
62 |
decorator = retry(try_max=2, try_timeout=0.1, |
63 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
64 |
- decorated_func = decorator(func_coroutine) |
65 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
66 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
67 |
self.assertEqual(len(done), 1) |
68 |
self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) |
69 |
@@ -124,7 +124,7 @@ class RetryTestCase(TestCase): |
70 |
func_coroutine = self._wrap_coroutine_func(HangForever()) |
71 |
decorator = retry(reraise=True, try_max=2, try_timeout=0.1, |
72 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
73 |
- decorated_func = decorator(func_coroutine) |
74 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
75 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
76 |
self.assertEqual(len(done), 1) |
77 |
self.assertTrue(isinstance(done.pop().exception(), asyncio.TimeoutError)) |
78 |
@@ -134,7 +134,7 @@ class RetryTestCase(TestCase): |
79 |
func_coroutine = self._wrap_coroutine_func(SucceedNever()) |
80 |
decorator = retry(try_timeout=0.1, |
81 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
82 |
- decorated_func = decorator(func_coroutine) |
83 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
84 |
future = decorated_func() |
85 |
loop.call_later(0.3, future.cancel) |
86 |
done, pending = loop.run_until_complete(asyncio.wait([future], loop=loop)) |
87 |
@@ -146,7 +146,7 @@ class RetryTestCase(TestCase): |
88 |
func_coroutine = self._wrap_coroutine_func(SucceedNever()) |
89 |
decorator = retry(try_timeout=0.1, overall_timeout=0.3, |
90 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
91 |
- decorated_func = decorator(func_coroutine) |
92 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
93 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
94 |
self.assertEqual(len(done), 1) |
95 |
self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) |
96 |
@@ -157,7 +157,7 @@ class RetryTestCase(TestCase): |
97 |
func_coroutine = self._wrap_coroutine_func(HangForever()) |
98 |
decorator = retry(try_timeout=0.1, overall_timeout=0.3, |
99 |
delay_func=RandomExponentialBackoff(multiplier=0.1, base=2)) |
100 |
- decorated_func = decorator(func_coroutine) |
101 |
+ decorated_func = decorator(func_coroutine, loop=loop) |
102 |
done, pending = loop.run_until_complete(asyncio.wait([decorated_func()], loop=loop)) |
103 |
self.assertEqual(len(done), 1) |
104 |
self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) |
105 |
|
106 |
diff --git a/pym/portage/util/futures/retry.py b/pym/portage/util/futures/retry.py |
107 |
index 8a51669ff..ccfc087ab 100644 |
108 |
--- a/pym/portage/util/futures/retry.py |
109 |
+++ b/pym/portage/util/futures/retry.py |
110 |
@@ -49,12 +49,12 @@ def retry(try_max=None, try_timeout=None, overall_timeout=None, |
111 |
overall_timeout, delay_func, reraise) |
112 |
|
113 |
|
114 |
-def _retry_wrapper(loop, try_max, try_timeout, overall_timeout, delay_func, |
115 |
- reraise, func): |
116 |
+def _retry_wrapper(_loop, try_max, try_timeout, overall_timeout, delay_func, |
117 |
+ reraise, func, loop=None): |
118 |
""" |
119 |
Create and return a decorated function. |
120 |
""" |
121 |
- return functools.partial(_retry, loop, try_max, try_timeout, |
122 |
+ return functools.partial(_retry, loop or _loop, try_max, try_timeout, |
123 |
overall_timeout, delay_func, reraise, func) |