You Might Not Want Async (in Python)

語言

中文演講/英文投影片

分類

Python Core(語言本身、標準函式庫…)

Python 難易度

進階

投影片連結

https://speakerdeck.com/uranusjr/you-might-not-want-async

摘要

Async programming is hot®, but also difficult. Since Python is fundamentally designed for sequential (as in “not parallel”) programming, asynchrony doesn’t feel natural, and requires more mentally to comprehend than, say, a language that can go async directly (bad pun intended).

This talk will try to talk you out of async programming in Python. The speaker will lay out reasons why async is the wrong programming model for you, and show various warts and pitfalls you are likely to encounter. He will also show hacks people put together to work around problems writing async programs, so that you know how awkward and unnatural async is in Python.

說明

Asynchrony in Python had gathered much momentum recently, with interests from core developers, as evidenced by the introduction of `asyncio` in Python 3.4, and a great boom of related third-party projects following it. By utilising more functionalities from the underlying operating system, it is a great solution to many existing problems in Python applications, gaining practical concurrency without working around the well-known GIL (global interpreter lock) problem. With all its advantages, asynchrony is, however, still a relatively new concept in Python, and as a result could be somewhat mistaken, even misunderstood by some people. One of these misconceptions, probably the most serious, is to mistake concurrency through asynchrony for parallelism. Although `asyncio` (and other similar solutions) lets multiple parts of your program executes without interfering each other, it does *not* allow them to run together—this is still impossible, at least in CPython, due to the continued existence of the GIL. This makes asynchrony suitable for only a certain, instead of all, kinds of problems. Evaluation is therefore required before a programmer can decide whether the asynchrony model is suitable for a particular application. Furthermore, partly due to its relatively short existence, paradigms in asynchrony programming do not necessarily fit well with other parts of Python, including libraries, either built-in or third-party ones. Since only blocking libraries were available in most of Python’s history, many assumptions they made may not work well with async programs out-of-the-box. Adopting asynchrony, at least at the present time, will therefore introduce more technical debt to your program. These are all important aspects that require much consideration before you dive head-first into asynchrony.

Tzu-ping Chung

TP builds his career around open source software, and enjoys committing his efforts to help make the world better. He builds all kinds of software for a living, from embedded system to single-page web applications, and contributes to the community when he can.

These days, he spends most of his time improving Python’s packaging landscape, organising PyCon Taiwan, and building software with Python and other modern technologies. He loves (human) languages, and knows probably too much about linguistics and phonetics to make him boring in parties.

TP 的職業生涯建立在開源軟體上,而喜歡花自己的精力讓這個世界更好。為了生活而寫過各式各樣的軟體,從嵌入式系統到 SPA 都是狩獵範圍,且只要有能力,就會盡量回饋社群。最近的時間大多花在對 Python packaging 的改善、籌辦 PyCon Taiwan、以及使用 Python 與現代前端技術開發軟體和應用程式。他有點太喜歡(人類)語言,常常扯到太多語言學和語音學,讓聊天內容變得無聊。