Re: [Python-Dev] Importance of "async" keyword

2015-07-03 Thread Nick Coghlan
On 3 July 2015 at 06:55, Sven R. Kunze  wrote:
> My understanding of coloring is "needs special treatment".
>
> Being special or not (containing an 'await' or not), as long as I don't need
> to care, I can call them either way (with 'await' or not) and each case
> works sensibly that's fine with me.

I'm afraid you're going to be disappointed in that regard, as wishing
that event driven programs behaved more like synchronous programs is
like wishing that complex numbers behaved like real numbers. There's
an extra level of complexity that is being deliberately introduced in
order to improve Python's ability to express certain kinds of
algorithms, and it isn't effective to just try to wish that complexity
away.

The payoff is that code that otherwise needs to be written as a long
series of disconnected callback chains (as has long been possible with
Twisted) can instead be written to look more like comparable
synchronous code (and this approach should bring with it much improved
introspection support, at least in 3.5+ now that gi_yieldfrom and
cr_await are being exposed at the Python level).

> Sensible would be something similar to:
> await function: suspension point and runs the function until completion
> call awaitable: runs the awaitable until completion

These both fail, and deliberately so: we don't know what they're
supposed to mean, and we refuse the temptation to guess. They're also
quite likely to indicate a bug (e.g. forgetting to call a native
coroutine function to get the coroutine out of it, forgetting to wait
for an awaitable) rather than something folks have done deliberately.

It's possible shorthand adapters may emerge over time, like:

# Call awaitable from synchronous code
def wait_for_result(awaitable):
"""Usage: result = asyncio.wait_for_result(awaitable)"""
   return asyncio.get_event_loop().run_until_complete(awaitable.__await__())

# Call blocking operation from asynchronous code
   def blocking_call(f, *args, **kwds):
"""Usage: result = await asyncio.blocking_call(f, *args, **kwds))"""
cb = functools.partial(f, *args, **kwds)
return asyncio.get_event_loop().run_in_executor(cb)

However, those can be written already as utility functions, so we can
wait and see how strong the demand is for them as adapters. (They may
also be potentially useful to have as recipes in the documentation)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Summary of Python tracker Issues

2015-07-03 Thread Python tracker

ACTIVITY SUMMARY (2015-06-26 - 2015-07-03)
Python tracker at http://bugs.python.org/

To view or respond to any of the issues listed below, click on the issue.
Do NOT respond to this message.

Issues counts and deltas:
  open4922 (+14)
  closed 31399 (+30)
  total  36321 (+44)

Open issues with patches: 2255 


Issues opened (27)
==

#3530: ast.NodeTransformer doc bug
http://bugs.python.org/issue3530  reopened by terry.reedy

#24400: Awaitable ABC incompatible with functools.singledispatch
http://bugs.python.org/issue24400  reopened by r.david.murray

#24458: Documentation for PEP 489
http://bugs.python.org/issue24458  reopened by ncoghlan

#24518: json.dumps should accept key function for ``sort_keys``
http://bugs.python.org/issue24518  opened by catherinedevlin

#24520: Stop using deprecated floating-point environment functions on 
http://bugs.python.org/issue24520  opened by Andrew Turner

#24524: python crash using Tkinter
http://bugs.python.org/issue24524  opened by tomnor

#24525: [doc] missing word
http://bugs.python.org/issue24525  opened by vincent-legoll

#24527: The MimeTypes class cannot ignore global files per instance
http://bugs.python.org/issue24527  opened by Sebastian Noack

#24531: please document that no code preceding encoding declaration is
http://bugs.python.org/issue24531  opened by jwilk

#24532: asyncio.sock_recv() blocks normal ioloop actions.
http://bugs.python.org/issue24532  opened by mmarkk

#24533: Increased Test Coverage for Lib/random.py
http://bugs.python.org/issue24533  opened by Charles Nodell

#24536: os.pipe() should return a structsequence (or namedtuple.)
http://bugs.python.org/issue24536  opened by jonathan.slenders

#24538: os.setxattr PermissionError on panfs propagates up causing `co
http://bugs.python.org/issue24538  opened by Gerrit.Holl

#24539: StreamReaderProtocol.eof_received() should return True to keep
http://bugs.python.org/issue24539  opened by gvanrossum

#24540: Documentation about skipkeys parameter for json.dumps is incor
http://bugs.python.org/issue24540  opened by Matthew Havard

#24542: ssl - SSL_OP_NO_TICKET not reimplemented
http://bugs.python.org/issue24542  opened by miniCruzer

#24544: Race condition and crash when embedding multi-thread script
http://bugs.python.org/issue24544  opened by Oleksiy Markovets

#24545: Issue with ssl package
http://bugs.python.org/issue24545  opened by kxl561

#24546: sequence index bug in random.choice
http://bugs.python.org/issue24546  opened by Serge Anuchin

#24548: Broken link in the unittest documentation
http://bugs.python.org/issue24548  opened by wau

#24549: string.format() should have a safe_substitute equivalent, to b
http://bugs.python.org/issue24549  opened by azrdev

#24550: maxint on 64 bit platforms breaks os.read
http://bugs.python.org/issue24550  opened by Brian Mingus

#24553: improve test coverage for subinterpreters
http://bugs.python.org/issue24553  opened by eric.snow

#24554: GC should happen when a subinterpreter is destroyed
http://bugs.python.org/issue24554  opened by eric.snow

#24555: Python logic error when deal with re and muti-threading
http://bugs.python.org/issue24555  opened by bee13oy

#24557: Refactor LibreSSL / EGD detection
http://bugs.python.org/issue24557  opened by spil

#24560: codecs.StreamReader doesn't work with nonblocking streams: Typ
http://bugs.python.org/issue24560  opened by yac



Most recent 15 issues with no replies (15)
==

#24560: codecs.StreamReader doesn't work with nonblocking streams: Typ
http://bugs.python.org/issue24560

#24557: Refactor LibreSSL / EGD detection
http://bugs.python.org/issue24557

#24550: maxint on 64 bit platforms breaks os.read
http://bugs.python.org/issue24550

#24548: Broken link in the unittest documentation
http://bugs.python.org/issue24548

#24542: ssl - SSL_OP_NO_TICKET not reimplemented
http://bugs.python.org/issue24542

#24539: StreamReaderProtocol.eof_received() should return True to keep
http://bugs.python.org/issue24539

#24527: The MimeTypes class cannot ignore global files per instance
http://bugs.python.org/issue24527

#24525: [doc] missing word
http://bugs.python.org/issue24525

#24524: python crash using Tkinter
http://bugs.python.org/issue24524

#24520: Stop using deprecated floating-point environment functions on 
http://bugs.python.org/issue24520

#24512: multiprocessing should log a warning when forking multithreade
http://bugs.python.org/issue24512

#24499: Python Installer text piles up during installation process
http://bugs.python.org/issue24499

#24498: Should ptags and eptags be removed from repo?
http://bugs.python.org/issue24498

#24477: In argparse subparser's option goes to parent parser
http://bugs.python.org/issue24477

#24466: extend_path explanation in documentation is ambiguous
http://bugs.python.org/issue24466



Most recent 15 issues waiting for review (15)
=

#24557: Refactor LibreSSL / EGD