[Python-checkins] peps: Strawman proposal for a flexible primitive to wait for one of a set of Futures.
guido.van.rossum
python-checkins at python.org
Wed Dec 19 06:40:22 CET 2012
http://hg.python.org/peps/rev/827d116d0a35
changeset: 4621:827d116d0a35
user: Guido van Rossum <guido at google.com>
date: Tue Dec 18 21:40:17 2012 -0800
summary:
Strawman proposal for a flexible primitive to wait for one of a set of Futures.
files:
pep-3156.txt | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/pep-3156.txt b/pep-3156.txt
--- a/pep-3156.txt
+++ b/pep-3156.txt
@@ -536,7 +536,7 @@
- ``writelines(iterable)``. Equivalent to::
for data in iterable:
- self.write(data)
+ self.write(data)
- ``write_eof()``. Close the writing end of the connection.
Subsequent calls to ``write()`` are not allowed. Once all buffered
@@ -838,10 +838,10 @@
caller (likely a transport) must then write code like this::
try:
- res = ev.sock_recv(sock, 8192)
+ res = ev.sock_recv(sock, 8192)
except Future as f:
- yield from sch.block_future(f)
- res = f.result()
+ yield from sch.block_future(f)
+ res = f.result()
- Do we need a larger vocabulary of operations for combining
coroutines and/or futures? E.g. in addition to par() we could have
@@ -852,6 +852,15 @@
syntax). Anyway, I think all of these are easy enough to write
using ``Task``.
+ Proposal: ``f = yield from wait_one(fs)`` takes a set of Futures and
+ sets f to the first of those that is done. (Yes, this requires an
+ intermediate Future to wait for.) You can then write::
+
+ while fs:
+ f = tulip.wait_one(fs)
+ fs.remove(f)
+ <inspect f>
+
- Task or callback priorities? (I hope not.)
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list