Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/_eventloop/
Date: Tue, 17 Jul 2018 19:07:09
Message-Id: 1531854338.ae8cc32ccd812661650647feffa1b10fc3ab5837.zmedico@gentoo
1 commit: ae8cc32ccd812661650647feffa1b10fc3ab5837
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jul 17 19:04:28 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 17 19:05:38 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ae8cc32c
7
8 EventLoop: add call_* context arg for python3.7 compat
9
10 The context argument currently does nothing, but exists for minimal
11 interoperability with Future instances that require it for PEP 567.
12
13 pym/portage/util/_eventloop/EventLoop.py | 26 ++++++++++++++++++++++----
14 1 file changed, 22 insertions(+), 4 deletions(-)
15
16 diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py
17 index df76374d9..69ccbac2c 100644
18 --- a/pym/portage/util/_eventloop/EventLoop.py
19 +++ b/pym/portage/util/_eventloop/EventLoop.py
20 @@ -832,7 +832,7 @@ class EventLoop(object):
21
22 return future.result()
23
24 - def call_soon(self, callback, *args):
25 + def call_soon(self, callback, *args, context=None):
26 """
27 Arrange for a callback to be called as soon as possible. The callback
28 is called after call_soon() returns, when control returns to the event
29 @@ -844,18 +844,25 @@ class EventLoop(object):
30 Any positional arguments after the callback will be passed to the
31 callback when it is called.
32
33 + The context argument currently does nothing, but exists for minimal
34 + interoperability with Future instances that require it for PEP 567.
35 +
36 An object compatible with asyncio.Handle is returned, which can
37 be used to cancel the callback.
38
39 @type callback: callable
40 @param callback: a function to call
41 + @type context: contextvars.Context
42 + @param context: An optional keyword-only context argument allows
43 + specifying a custom contextvars.Context for the callback to run
44 + in. The current context is used when no context is provided.
45 @return: a handle which can be used to cancel the callback
46 @rtype: asyncio.Handle (or compatible)
47 """
48 return self._handle(self._idle_add(
49 self._call_soon_callback(callback, args)), self)
50
51 - def call_soon_threadsafe(self, callback, *args):
52 + def call_soon_threadsafe(self, callback, *args, context=None):
53 """Like call_soon(), but thread safe."""
54 # idle_add provides thread safety
55 return self._handle(self.idle_add(
56 @@ -870,7 +877,7 @@ class EventLoop(object):
57 """
58 return monotonic()
59
60 - def call_later(self, delay, callback, *args):
61 + def call_later(self, delay, callback, *args, context=None):
62 """
63 Arrange for the callback to be called after the given delay seconds
64 (either an int or float).
65 @@ -886,19 +893,26 @@ class EventLoop(object):
66 it is called. If you want the callback to be called with some named
67 arguments, use a closure or functools.partial().
68
69 + The context argument currently does nothing, but exists for minimal
70 + interoperability with Future instances that require it for PEP 567.
71 +
72 Use functools.partial to pass keywords to the callback.
73
74 @type delay: int or float
75 @param delay: delay seconds
76 @type callback: callable
77 @param callback: a function to call
78 + @type context: contextvars.Context
79 + @param context: An optional keyword-only context argument allows
80 + specifying a custom contextvars.Context for the callback to run
81 + in. The current context is used when no context is provided.
82 @return: a handle which can be used to cancel the callback
83 @rtype: asyncio.Handle (or compatible)
84 """
85 return self._handle(self.timeout_add(
86 delay * 1000, self._call_soon_callback(callback, args)), self)
87
88 - def call_at(self, when, callback, *args):
89 + def call_at(self, when, callback, *args, context=None):
90 """
91 Arrange for the callback to be called at the given absolute
92 timestamp when (an int or float), using the same time reference as
93 @@ -915,6 +929,10 @@ class EventLoop(object):
94 @param when: absolute timestamp when to call callback
95 @type callback: callable
96 @param callback: a function to call
97 + @type context: contextvars.Context
98 + @param context: An optional keyword-only context argument allows
99 + specifying a custom contextvars.Context for the callback to run
100 + in. The current context is used when no context is provided.
101 @return: a handle which can be used to cancel the callback
102 @rtype: asyncio.Handle (or compatible)
103 """