From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A5D36138334 for ; Tue, 17 Jul 2018 19:07:09 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 99650E0AB4; Tue, 17 Jul 2018 19:07:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 60D01E0AB4 for ; Tue, 17 Jul 2018 19:07:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D1B02335C96 for ; Tue, 17 Jul 2018 19:07:06 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 29E9D35F for ; Tue, 17 Jul 2018 19:07:05 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1531854338.ae8cc32ccd812661650647feffa1b10fc3ab5837.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/_eventloop/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/util/_eventloop/EventLoop.py X-VCS-Directories: pym/portage/util/_eventloop/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: ae8cc32ccd812661650647feffa1b10fc3ab5837 X-VCS-Branch: master Date: Tue, 17 Jul 2018 19:07:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d43bafbc-8188-481e-b543-09304d45ec9d X-Archives-Hash: af672a0f4185c0d583c2bdd188ad747c commit: ae8cc32ccd812661650647feffa1b10fc3ab5837 Author: Zac Medico gentoo org> AuthorDate: Tue Jul 17 19:04:28 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Tue Jul 17 19:05:38 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ae8cc32c EventLoop: add call_* context arg for python3.7 compat The context argument currently does nothing, but exists for minimal interoperability with Future instances that require it for PEP 567. pym/portage/util/_eventloop/EventLoop.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py index df76374d9..69ccbac2c 100644 --- a/pym/portage/util/_eventloop/EventLoop.py +++ b/pym/portage/util/_eventloop/EventLoop.py @@ -832,7 +832,7 @@ class EventLoop(object): return future.result() - def call_soon(self, callback, *args): + def call_soon(self, callback, *args, context=None): """ Arrange for a callback to be called as soon as possible. The callback is called after call_soon() returns, when control returns to the event @@ -844,18 +844,25 @@ class EventLoop(object): Any positional arguments after the callback will be passed to the callback when it is called. + The context argument currently does nothing, but exists for minimal + interoperability with Future instances that require it for PEP 567. + An object compatible with asyncio.Handle is returned, which can be used to cancel the callback. @type callback: callable @param callback: a function to call + @type context: contextvars.Context + @param context: An optional keyword-only context argument allows + specifying a custom contextvars.Context for the callback to run + in. The current context is used when no context is provided. @return: a handle which can be used to cancel the callback @rtype: asyncio.Handle (or compatible) """ return self._handle(self._idle_add( self._call_soon_callback(callback, args)), self) - def call_soon_threadsafe(self, callback, *args): + def call_soon_threadsafe(self, callback, *args, context=None): """Like call_soon(), but thread safe.""" # idle_add provides thread safety return self._handle(self.idle_add( @@ -870,7 +877,7 @@ class EventLoop(object): """ return monotonic() - def call_later(self, delay, callback, *args): + def call_later(self, delay, callback, *args, context=None): """ Arrange for the callback to be called after the given delay seconds (either an int or float). @@ -886,19 +893,26 @@ class EventLoop(object): it is called. If you want the callback to be called with some named arguments, use a closure or functools.partial(). + The context argument currently does nothing, but exists for minimal + interoperability with Future instances that require it for PEP 567. + Use functools.partial to pass keywords to the callback. @type delay: int or float @param delay: delay seconds @type callback: callable @param callback: a function to call + @type context: contextvars.Context + @param context: An optional keyword-only context argument allows + specifying a custom contextvars.Context for the callback to run + in. The current context is used when no context is provided. @return: a handle which can be used to cancel the callback @rtype: asyncio.Handle (or compatible) """ return self._handle(self.timeout_add( delay * 1000, self._call_soon_callback(callback, args)), self) - def call_at(self, when, callback, *args): + def call_at(self, when, callback, *args, context=None): """ Arrange for the callback to be called at the given absolute timestamp when (an int or float), using the same time reference as @@ -915,6 +929,10 @@ class EventLoop(object): @param when: absolute timestamp when to call callback @type callback: callable @param callback: a function to call + @type context: contextvars.Context + @param context: An optional keyword-only context argument allows + specifying a custom contextvars.Context for the callback to run + in. The current context is used when no context is provided. @return: a handle which can be used to cancel the callback @rtype: asyncio.Handle (or compatible) """