Re: [gentoo-portage-dev] [PATCH] Future: implement add_done_callback for asyncio compat (bug 591760)
On Sun, Mar 26, 2017 at 12:07 PM, Brian Dolbecwrote: > On Sun, 26 Mar 2017 03:13:11 -0700 > Zac Medico wrote: > >> Implement the add_done_callback and remove_done_callback methods, >> since they are required in order to make further progress toward >> asyncio compatibility. >> >> Also implement the AbstractEventLoop create_future method for the >> EventLoop class, so that it returns an instance of _EventLoopFuture. >> EventLoop currently does not implement some of the >> asyncio.AbstractEventLoop methods that asyncio.Future requires for >> its add_done_callback implementation, and the create_future method >> conveniently solves this problem. >> >> X-Gentoo-bug: 591760 >> X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=591760 >> --- >> pym/portage/tests/ebuild/test_ipc_daemon.py| 3 +- >> .../tests/util/eventloop/test_call_soon_fifo.py| 6 +- >> pym/portage/tests/util/futures/__init__.py | 0 >> pym/portage/tests/util/futures/__test__.py | 0 >> .../tests/util/futures/test_done_callback.py | 35 + >> pym/portage/util/_async/SchedulerInterface.py | 3 +- >> pym/portage/util/_eventloop/EventLoop.py | 14 >> pym/portage/util/futures/futures.py| 82 >> -- 8 files changed, 132 insertions(+), 11 >> deletions(-) create mode 100644 >> pym/portage/tests/util/futures/__init__.py create mode 100644 >> pym/portage/tests/util/futures/__test__.py create mode 100644 >> pym/portage/tests/util/futures/test_done_callback.py >> > > looks fine... /me ignoring the lack of parameters descriptions in the > docstrings Yeah, I skipped parameter docstrings because the interfaces are compatible with the python standard libraries. Pushed: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4b12ed04ec6b99f5a948e0eea5778a4fac502740 -- Thanks, Zac
Re: [gentoo-portage-dev] [PATCH] Future: implement add_done_callback for asyncio compat (bug 591760)
On Sun, 26 Mar 2017 03:13:11 -0700 Zac Medicowrote: > Implement the add_done_callback and remove_done_callback methods, > since they are required in order to make further progress toward > asyncio compatibility. > > Also implement the AbstractEventLoop create_future method for the > EventLoop class, so that it returns an instance of _EventLoopFuture. > EventLoop currently does not implement some of the > asyncio.AbstractEventLoop methods that asyncio.Future requires for > its add_done_callback implementation, and the create_future method > conveniently solves this problem. > > X-Gentoo-bug: 591760 > X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=591760 > --- > pym/portage/tests/ebuild/test_ipc_daemon.py| 3 +- > .../tests/util/eventloop/test_call_soon_fifo.py| 6 +- > pym/portage/tests/util/futures/__init__.py | 0 > pym/portage/tests/util/futures/__test__.py | 0 > .../tests/util/futures/test_done_callback.py | 35 + > pym/portage/util/_async/SchedulerInterface.py | 3 +- > pym/portage/util/_eventloop/EventLoop.py | 14 > pym/portage/util/futures/futures.py| 82 > -- 8 files changed, 132 insertions(+), 11 > deletions(-) create mode 100644 > pym/portage/tests/util/futures/__init__.py create mode 100644 > pym/portage/tests/util/futures/__test__.py create mode 100644 > pym/portage/tests/util/futures/test_done_callback.py > > diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py > b/pym/portage/tests/ebuild/test_ipc_daemon.py index 68f139a..fc79165 > 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py > +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py > @@ -16,7 +16,6 @@ from portage.util import ensure_dirs > from portage.util._async.ForkProcess import ForkProcess > from portage.util._async.TaskScheduler import TaskScheduler > from portage.util._eventloop.global_event_loop import > global_event_loop -from portage.util.futures.futures import Future > from _emerge.SpawnProcess import SpawnProcess > from _emerge.EbuildBuildDir import EbuildBuildDir > from _emerge.EbuildIpcDaemon import EbuildIpcDaemon > @@ -150,7 +149,7 @@ class IpcDaemonTestCase(TestCase): > self._run_done.set_result(True) > > def _run(self, event_loop, task_scheduler, timeout): > - self._run_done = Future() > + self._run_done = event_loop.create_future() > timeout_id = event_loop.timeout_add(timeout, > self._timeout_callback, task_scheduler) > task_scheduler.addExitListener(self._exit_callback) > diff --git a/pym/portage/tests/util/eventloop/test_call_soon_fifo.py > b/pym/portage/tests/util/eventloop/test_call_soon_fifo.py index > 5ecc13f..f970c67 100644 --- > a/pym/portage/tests/util/eventloop/test_call_soon_fifo.py +++ > b/pym/portage/tests/util/eventloop/test_call_soon_fifo.py @@ -7,22 > +7,22 @@ import random from portage import os > from portage.tests import TestCase > from portage.util._eventloop.global_event_loop import > global_event_loop -from portage.util.futures.futures import Future > + > > class CallSoonFifoTestCase(TestCase): > > def testCallSoonFifo(self): > > + event_loop = global_event_loop() > inputs = [random.random() for index in range(10)] > outputs = [] > - finished = Future() > + finished = event_loop.create_future() > > def add_output(value): > outputs.append(value) > if len(outputs) == len(inputs): > finished.set_result(True) > > - event_loop = global_event_loop() > for value in inputs: > event_loop.call_soon(functools.partial(add_output, > value)) > diff --git a/pym/portage/tests/util/futures/__init__.py > b/pym/portage/tests/util/futures/__init__.py new file mode 100644 > index 000..e69de29 > diff --git a/pym/portage/tests/util/futures/__test__.py > b/pym/portage/tests/util/futures/__test__.py new file mode 100644 > index 000..e69de29 > diff --git a/pym/portage/tests/util/futures/test_done_callback.py > b/pym/portage/tests/util/futures/test_done_callback.py new file mode > 100644 index 000..76b727b > --- /dev/null > +++ b/pym/portage/tests/util/futures/test_done_callback.py > @@ -0,0 +1,35 @@ > +# Copyright 2017 Gentoo Foundation > +# Distributed under the terms of the GNU General Public License v2 > + > +from portage.tests import TestCase > +from portage.util._eventloop.global_event_loop import > global_event_loop + > + > +class FutureDoneCallbackTestCase(TestCase): > + > + def testFutureDoneCallback(self): > + > + event_loop = global_event_loop() > + > + def done_callback(finished): > + done_callback_called.set_result(True) > + > + done_callback_called =
[gentoo-portage-dev] [PATCH] Future: implement add_done_callback for asyncio compat (bug 591760)
Implement the add_done_callback and remove_done_callback methods, since they are required in order to make further progress toward asyncio compatibility. Also implement the AbstractEventLoop create_future method for the EventLoop class, so that it returns an instance of _EventLoopFuture. EventLoop currently does not implement some of the asyncio.AbstractEventLoop methods that asyncio.Future requires for its add_done_callback implementation, and the create_future method conveniently solves this problem. X-Gentoo-bug: 591760 X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=591760 --- pym/portage/tests/ebuild/test_ipc_daemon.py| 3 +- .../tests/util/eventloop/test_call_soon_fifo.py| 6 +- pym/portage/tests/util/futures/__init__.py | 0 pym/portage/tests/util/futures/__test__.py | 0 .../tests/util/futures/test_done_callback.py | 35 + pym/portage/util/_async/SchedulerInterface.py | 3 +- pym/portage/util/_eventloop/EventLoop.py | 14 pym/portage/util/futures/futures.py| 82 -- 8 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 pym/portage/tests/util/futures/__init__.py create mode 100644 pym/portage/tests/util/futures/__test__.py create mode 100644 pym/portage/tests/util/futures/test_done_callback.py diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index 68f139a..fc79165 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -16,7 +16,6 @@ from portage.util import ensure_dirs from portage.util._async.ForkProcess import ForkProcess from portage.util._async.TaskScheduler import TaskScheduler from portage.util._eventloop.global_event_loop import global_event_loop -from portage.util.futures.futures import Future from _emerge.SpawnProcess import SpawnProcess from _emerge.EbuildBuildDir import EbuildBuildDir from _emerge.EbuildIpcDaemon import EbuildIpcDaemon @@ -150,7 +149,7 @@ class IpcDaemonTestCase(TestCase): self._run_done.set_result(True) def _run(self, event_loop, task_scheduler, timeout): - self._run_done = Future() + self._run_done = event_loop.create_future() timeout_id = event_loop.timeout_add(timeout, self._timeout_callback, task_scheduler) task_scheduler.addExitListener(self._exit_callback) diff --git a/pym/portage/tests/util/eventloop/test_call_soon_fifo.py b/pym/portage/tests/util/eventloop/test_call_soon_fifo.py index 5ecc13f..f970c67 100644 --- a/pym/portage/tests/util/eventloop/test_call_soon_fifo.py +++ b/pym/portage/tests/util/eventloop/test_call_soon_fifo.py @@ -7,22 +7,22 @@ import random from portage import os from portage.tests import TestCase from portage.util._eventloop.global_event_loop import global_event_loop -from portage.util.futures.futures import Future + class CallSoonFifoTestCase(TestCase): def testCallSoonFifo(self): + event_loop = global_event_loop() inputs = [random.random() for index in range(10)] outputs = [] - finished = Future() + finished = event_loop.create_future() def add_output(value): outputs.append(value) if len(outputs) == len(inputs): finished.set_result(True) - event_loop = global_event_loop() for value in inputs: event_loop.call_soon(functools.partial(add_output, value)) diff --git a/pym/portage/tests/util/futures/__init__.py b/pym/portage/tests/util/futures/__init__.py new file mode 100644 index 000..e69de29 diff --git a/pym/portage/tests/util/futures/__test__.py b/pym/portage/tests/util/futures/__test__.py new file mode 100644 index 000..e69de29 diff --git a/pym/portage/tests/util/futures/test_done_callback.py b/pym/portage/tests/util/futures/test_done_callback.py new file mode 100644 index 000..76b727b --- /dev/null +++ b/pym/portage/tests/util/futures/test_done_callback.py @@ -0,0 +1,35 @@ +# Copyright 2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +from portage.tests import TestCase +from portage.util._eventloop.global_event_loop import global_event_loop + + +class FutureDoneCallbackTestCase(TestCase): + + def testFutureDoneCallback(self): + + event_loop = global_event_loop() + + def done_callback(finished): + done_callback_called.set_result(True) + + done_callback_called = event_loop.create_future() + finished = event_loop.create_future() + finished.add_done_callback(done_callback) + event_loop.call_soon(finished.set_result, True) +